File: fake_suggestion_handler.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (95 lines) | stat: -rw-r--r-- 4,141 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ASH_INPUT_METHOD_FAKE_SUGGESTION_HANDLER_H_
#define CHROME_BROWSER_ASH_INPUT_METHOD_FAKE_SUGGESTION_HANDLER_H_

#include "chrome/browser/ash/input_method/assistive_window_properties.h"
#include "chrome/browser/ash/input_method/suggestion_handler_interface.h"
#include "chrome/browser/ui/ash/input_method/suggestion_details.h"

namespace ash {
namespace input_method {

// Fake suggestion handler used for testing.
//
// TODO(crbug/1201529): This class has borrowed heavily from the
// `TestSuggestionHandler` class in personal_info_suggester_unittest.cc. That
// class included a number of testing assertions within the fake whereas this
// class does not. In future CLs we should remove the `TestSuggestionHandler`
// class from personal_info_suggester_unittest.cc and replace it with this
// class.
class FakeSuggestionHandler : public SuggestionHandlerInterface {
 public:
  FakeSuggestionHandler();
  ~FakeSuggestionHandler() override;

  // SuggestionHandlerInterface overrides
  bool DismissSuggestion(int context_id, std::string* error) override;
  bool SetSuggestion(int context_id,
                     const ui::ime::SuggestionDetails& details,
                     std::string* error) override;
  bool AcceptSuggestion(int context_id, std::string* error) override;
  void OnSuggestionsChanged(
      const std::vector<std::string>& suggestions) override;
  bool SetButtonHighlighted(int context_id,
                            const ui::ime::AssistiveWindowButton& button,
                            bool highlighted,
                            std::string* error) override;
  void ClickButton(const ui::ime::AssistiveWindowButton& button) override;
  bool AcceptSuggestionCandidate(int context_id,
                                 const std::u16string& candidate,
                                 size_t delete_previous_utf16_len,
                                 std::string* error) override;
  bool SetAssistiveWindowProperties(
      int context_id,
      const AssistiveWindowProperties& assistive_window,
      std::string* error) override;
  void Announce(const std::u16string& message) override;

  // Test getters
  int GetContextId() { return context_id_; }
  std::u16string GetSuggestionText() { return suggestion_text_; }
  std::u16string GetAcceptedSuggestionText() {
    return accepted_suggestion_text_;
  }
  size_t GetConfirmedLength() { return confirmed_length_; }
  size_t GetDeletePreviousUtf16Len() { return delete_previous_utf16_len_; }
  bool GetShowingSuggestion() { return showing_suggestion_; }
  bool GetAcceptedSuggestion() { return accepted_suggestion_; }
  bool GetDismissedSuggestion() { return dismissed_suggestion_; }
  bool GetHighlightedSuggestion() { return highlighted_suggestion_; }
  ui::ime::AssistiveWindowButton GetHighlightedButton() {
    return highlighted_button_;
  }
  std::vector<std::u16string> GetAnnouncements() { return announcements_; }
  std::vector<std::string> GetLastOnSuggestionChangedEventSuggestions() {
    return last_on_suggestion_changed_event_suggestions_;
  }
  ui::ime::SuggestionDetails GetLastSuggestionDetails() {
    return last_suggestion_details_;
  }
  ui::ime::ButtonId GetLastClickedButton() { return last_clicked_button_; }

 private:
  int context_id_ = 0;
  std::u16string suggestion_text_;
  std::u16string accepted_suggestion_text_;
  size_t confirmed_length_ = 0;
  size_t delete_previous_utf16_len_ = 0;
  bool showing_suggestion_ = false;
  bool accepted_suggestion_ = false;
  bool dismissed_suggestion_ = false;
  bool highlighted_suggestion_ = false;
  ui::ime::AssistiveWindowButton highlighted_button_;
  std::vector<std::u16string> announcements_;
  std::vector<std::string> last_on_suggestion_changed_event_suggestions_;
  ui::ime::SuggestionDetails last_suggestion_details_;
  ui::ime::ButtonId last_clicked_button_ = ui::ime::ButtonId::kNone;
};

}  // namespace input_method
}  // namespace ash

#endif  // CHROME_BROWSER_ASH_INPUT_METHOD_FAKE_SUGGESTION_HANDLER_H_