Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Side by Side Diff: components/web_view/web_view_apptest.cc

Issue 1371773003: mandoline: Add find in page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix spacing on the right side of the UI. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/web_view/public/cpp/web_view.h" 5 #include "components/web_view/public/cpp/web_view.h"
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "components/mus/public/cpp/scoped_view_ptr.h" 13 #include "components/mus/public/cpp/scoped_view_ptr.h"
14 #include "components/mus/public/cpp/tests/view_manager_test_base.h" 14 #include "components/mus/public/cpp/tests/view_manager_test_base.h"
15 #include "components/mus/public/cpp/view.h" 15 #include "components/mus/public/cpp/view.h"
16 #include "components/mus/public/cpp/view_tree_connection.h" 16 #include "components/mus/public/cpp/view_tree_connection.h"
17 #include "mojo/util/filename_util.h" 17 #include "mojo/util/filename_util.h"
18 #include "url/gurl.h" 18 #include "url/gurl.h"
19 19
20 namespace web_view { 20 namespace web_view {
21 21
22 namespace { 22 namespace {
23 const char kTestOneFile[] = "test_one.html"; 23 const char kTestOneFile[] = "test_one.html";
24 const char kTestOneTitle[] = "Test Title One"; 24 const char kTestOneTitle[] = "Test Title One";
25 const char kTestTwoFile[] = "test_two.html"; 25 const char kTestTwoFile[] = "test_two.html";
26 const char kTestTwoTitle[] = "Test Title Two"; 26 const char kTestTwoTitle[] = "Test Title Two";
27 const char kTestThreeFile[] = "test_three.html"; 27 const char kTestThreeFile[] = "test_three.html";
28 const char kTestThreeTitle[] = "Test Title Three"; 28 const char kTestThreeTitle[] = "Test Title Three";
29 const char kTheWordGreenFiveTimes[] = "the_word_green_five_times.html";
29 30
30 GURL GetTestFileURL(const std::string& file) { 31 GURL GetTestFileURL(const std::string& file) {
31 base::FilePath data_file; 32 base::FilePath data_file;
32 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &data_file)); 33 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &data_file));
33 data_file = data_file.AppendASCII("components/test/data/web_view") 34 data_file = data_file.AppendASCII("components/test/data/web_view")
34 .AppendASCII(file) 35 .AppendASCII(file)
35 .NormalizePathSeparators(); 36 .NormalizePathSeparators();
36 CHECK(base::PathExists(data_file)); 37 CHECK(base::PathExists(data_file));
37 return mojo::util::FilePathToFileURL(data_file); 38 return mojo::util::FilePathToFileURL(data_file);
38 } 39 }
40
39 } 41 }
40 42
41 class WebViewTest : public mus::ViewManagerTestBase, 43 class WebViewTest : public mus::ViewManagerTestBase,
42 public mojom::WebViewClient { 44 public mojom::WebViewClient {
43 public: 45 public:
44 WebViewTest() : web_view_(this) {} 46 WebViewTest() : web_view_(this), active_find_match_(0), find_count_(0) {}
45 ~WebViewTest() override {} 47 ~WebViewTest() override {}
46 48
47 mojom::WebView* web_view() { return web_view_.web_view(); } 49 mojom::WebView* web_view() { return web_view_.web_view(); }
48 50
49 const std::string& navigation_url() const { return navigation_url_; } 51 const std::string& navigation_url() const { return navigation_url_; }
50 const std::string& last_title() const { return last_title_; } 52 const std::string& last_title() const { return last_title_; }
51 mojom::ButtonState last_back_button_state() { 53 mojom::ButtonState last_back_button_state() {
52 return last_back_button_state_; 54 return last_back_button_state_;
53 } 55 }
54 mojom::ButtonState last_forward_button_state() { 56 mojom::ButtonState last_forward_button_state() {
55 return last_forward_button_state_; 57 return last_forward_button_state_;
56 } 58 }
57 59
60 int32_t active_find_match() const { return active_find_match_; }
61 int32_t find_count() const { return find_count_; }
62
58 void StartNestedRunLoopUntilLoadingDone() { 63 void StartNestedRunLoopUntilLoadingDone() {
59 run_loop_.reset(new base::RunLoop); 64 run_loop_.reset(new base::RunLoop);
60 run_loop_->Run(); 65 run_loop_->Run();
61 } 66 }
62 67
63 void NavigateTo(const std::string& file) { 68 void NavigateTo(const std::string& file) {
64 mojo::URLRequestPtr request(mojo::URLRequest::New()); 69 mojo::URLRequestPtr request(mojo::URLRequest::New());
65 request->url = GetTestFileURL(file).spec(); 70 request->url = GetTestFileURL(file).spec();
66 web_view()->LoadRequest(request.Pass()); 71 web_view()->LoadRequest(request.Pass());
67 StartNestedRunLoopUntilLoadingDone(); 72 StartNestedRunLoopUntilLoadingDone();
68 } 73 }
69 74
70 private: 75 private:
71 void QuitNestedRunLoop() { 76 void QuitNestedRunLoop() {
72 if (run_loop_) { 77 if (run_loop_) {
73 run_loop_->Quit(); 78 run_loop_->Quit();
74 } 79 }
75 } 80 }
76 81
77 // Overridden from ApplicationDelegate: 82 // Overridden from ApplicationDelegate:
78 void Initialize(mojo::ApplicationImpl* app) override { 83 void Initialize(mojo::ApplicationImpl* app) override {
79 ViewManagerTestBase::Initialize(app); 84 ViewManagerTestBase::Initialize(app);
80 app_ = app; 85 app_ = app;
81 } 86 }
82 87
83 // Overridden from ViewTreeDelegate: 88 // Overridden from ViewTreeDelegate:
84 void OnEmbed(mus::View* root) override { 89 void OnEmbed(mus::View* root) override {
85 content_ = root->connection()->CreateView(); 90 content_ = root->connection()->CreateView();
91 content_->SetBounds(root->bounds());
86 root->AddChild(content_); 92 root->AddChild(content_);
87 content_->SetVisible(true); 93 content_->SetVisible(true);
88 94
89 web_view_.Init(app_, content_); 95 web_view_.Init(app_, content_);
90 96
91 ViewManagerTestBase::OnEmbed(root); 97 ViewManagerTestBase::OnEmbed(root);
92 } 98 }
93 99
94 void TearDown() override { 100 void TearDown() override {
95 mus::ScopedViewPtr::DeleteViewOrViewManager(window_manager()->GetRoot()); 101 mus::ScopedViewPtr::DeleteViewOrViewManager(window_manager()->GetRoot());
(...skipping 10 matching lines...) Expand all
106 QuitNestedRunLoop(); 112 QuitNestedRunLoop();
107 } 113 }
108 void BackForwardChanged(mojom::ButtonState back_button, 114 void BackForwardChanged(mojom::ButtonState back_button,
109 mojom::ButtonState forward_button) override { 115 mojom::ButtonState forward_button) override {
110 last_back_button_state_ = back_button; 116 last_back_button_state_ = back_button;
111 last_forward_button_state_ = forward_button; 117 last_forward_button_state_ = forward_button;
112 } 118 }
113 void TitleChanged(const mojo::String& title) override { 119 void TitleChanged(const mojo::String& title) override {
114 last_title_ = title.get(); 120 last_title_ = title.get();
115 } 121 }
122 void ReportFindInPageMatchCount(int32_t request_id,
123 int32_t count,
124 bool final_update) override {
125 find_count_ = count;
126 if (final_update)
127 QuitNestedRunLoop();
128 }
129 void ReportFindInPageSelection(int32_t request_id,
130 int32_t active_match_ordinal) override {
131 active_find_match_ = active_match_ordinal;
132 }
116 133
117 mojo::ApplicationImpl* app_; 134 mojo::ApplicationImpl* app_;
118 135
119 mus::View* content_; 136 mus::View* content_;
120 137
121 web_view::WebView web_view_; 138 web_view::WebView web_view_;
122 139
123 scoped_ptr<base::RunLoop> run_loop_; 140 scoped_ptr<base::RunLoop> run_loop_;
124 141
125 std::string navigation_url_; 142 std::string navigation_url_;
126 std::string last_title_; 143 std::string last_title_;
127 mojom::ButtonState last_back_button_state_; 144 mojom::ButtonState last_back_button_state_;
128 mojom::ButtonState last_forward_button_state_; 145 mojom::ButtonState last_forward_button_state_;
129 146
147 int32_t active_find_match_;
148 int32_t find_count_;
149
130 DISALLOW_COPY_AND_ASSIGN(WebViewTest); 150 DISALLOW_COPY_AND_ASSIGN(WebViewTest);
131 }; 151 };
132 152
133 TEST_F(WebViewTest, TestTitleChanged) { 153 TEST_F(WebViewTest, TestTitleChanged) {
134 ASSERT_NO_FATAL_FAILURE(NavigateTo(kTestOneFile)); 154 ASSERT_NO_FATAL_FAILURE(NavigateTo(kTestOneFile));
135 155
136 // Our title should have been set on the navigation. 156 // Our title should have been set on the navigation.
137 EXPECT_EQ(kTestOneTitle, last_title()); 157 EXPECT_EQ(kTestOneTitle, last_title());
138 } 158 }
139 159
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 // Now navigate to a third file. This should clear the forward stack. 214 // Now navigate to a third file. This should clear the forward stack.
195 ASSERT_NO_FATAL_FAILURE(NavigateTo(kTestThreeFile)); 215 ASSERT_NO_FATAL_FAILURE(NavigateTo(kTestThreeFile));
196 216
197 EXPECT_EQ(GetTestFileURL(kTestThreeFile).spec(), navigation_url()); 217 EXPECT_EQ(GetTestFileURL(kTestThreeFile).spec(), navigation_url());
198 EXPECT_EQ(kTestThreeTitle, last_title()); 218 EXPECT_EQ(kTestThreeTitle, last_title());
199 EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_ENABLED, last_back_button_state()); 219 EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_ENABLED, last_back_button_state());
200 EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_DISABLED, 220 EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_DISABLED,
201 last_forward_button_state()); 221 last_forward_button_state());
202 } 222 }
203 223
224 TEST_F(WebViewTest, Find) {
225 ASSERT_NO_FATAL_FAILURE(NavigateTo(kTheWordGreenFiveTimes));
226
227 web_view()->Find(1, "Green");
228 StartNestedRunLoopUntilLoadingDone();
229 EXPECT_EQ(1, active_find_match());
230 EXPECT_EQ(5, find_count());
231 }
232
204 } // namespace web_view 233 } // namespace web_view
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698