Chromium Code Reviews| Index: components/web_view/web_view_apptest.cc |
| diff --git a/components/web_view/web_view_apptest.cc b/components/web_view/web_view_apptest.cc |
| index 130ef0a22e1baa079be89cd19a3fa43e1875af47..8366be592abda0c46588b575057ff390d1335159 100644 |
| --- a/components/web_view/web_view_apptest.cc |
| +++ b/components/web_view/web_view_apptest.cc |
| @@ -26,6 +26,8 @@ const char kTestTwoFile[] = "test_two.html"; |
| const char kTestTwoTitle[] = "Test Title Two"; |
| const char kTestThreeFile[] = "test_three.html"; |
| const char kTestThreeTitle[] = "Test Title Three"; |
| +const char kTheWordGreenFiveTimes[] = "the_word_green_five_times.html"; |
| +const char kTwoIframesWithGreen[] = "two_iframes_with_green.html"; |
| GURL GetTestFileURL(const std::string& file) { |
| base::FilePath data_file; |
| @@ -36,12 +38,17 @@ GURL GetTestFileURL(const std::string& file) { |
| CHECK(base::PathExists(data_file)); |
| return mojo::util::FilePathToFileURL(data_file); |
| } |
| + |
| } |
| class WebViewTest : public mus::ViewManagerTestBase, |
| public mojom::WebViewClient { |
| public: |
| - WebViewTest() : web_view_(this) {} |
| + WebViewTest() |
| + : web_view_(this), |
| + quit_condition_(NO_QUIT), |
| + active_find_match_(0), |
| + find_count_(0) {} |
| ~WebViewTest() override {} |
| mojom::WebView* web_view() { return web_view_.web_view(); } |
| @@ -55,7 +62,17 @@ class WebViewTest : public mus::ViewManagerTestBase, |
| return last_forward_button_state_; |
| } |
| - void StartNestedRunLoopUntilLoadingDone() { |
| + int32_t active_find_match() const { return active_find_match_; } |
| + int32_t find_count() const { return find_count_; } |
| + |
| + enum NestedLoopQuitCondition { |
| + NO_QUIT, |
| + LOADING_DONE, |
| + FINAL_FIND_UPATE, |
| + }; |
| + |
| + void StartNestedRunLoopUntil(NestedLoopQuitCondition quit_condition) { |
| + quit_condition_ = quit_condition; |
| run_loop_.reset(new base::RunLoop); |
| run_loop_->Run(); |
| } |
| @@ -64,12 +81,13 @@ class WebViewTest : public mus::ViewManagerTestBase, |
| mojo::URLRequestPtr request(mojo::URLRequest::New()); |
| request->url = GetTestFileURL(file).spec(); |
| web_view()->LoadRequest(request.Pass()); |
| - StartNestedRunLoopUntilLoadingDone(); |
| + StartNestedRunLoopUntil(LOADING_DONE); |
| } |
| private: |
| void QuitNestedRunLoop() { |
| if (run_loop_) { |
| + quit_condition_ = NO_QUIT; |
| run_loop_->Quit(); |
| } |
| } |
| @@ -83,6 +101,7 @@ class WebViewTest : public mus::ViewManagerTestBase, |
| // Overridden from ViewTreeDelegate: |
| void OnEmbed(mus::View* root) override { |
| content_ = root->connection()->CreateView(); |
| + content_->SetBounds(root->bounds()); |
| root->AddChild(content_); |
| content_->SetVisible(true); |
| @@ -102,8 +121,8 @@ class WebViewTest : public mus::ViewManagerTestBase, |
| navigation_url_ = url.get(); |
| } |
| void LoadingStateChanged(bool is_loading, double progress) override { |
| - if (is_loading == false) |
| - QuitNestedRunLoop(); |
| + if (is_loading == false && quit_condition_ == LOADING_DONE) |
| + QuitNestedRunLoop(); |
| } |
| void BackForwardChanged(mojom::ButtonState back_button, |
| mojom::ButtonState forward_button) override { |
| @@ -113,6 +132,17 @@ class WebViewTest : public mus::ViewManagerTestBase, |
| void TitleChanged(const mojo::String& title) override { |
| last_title_ = title.get(); |
| } |
| + void ReportFindInPageMatchCount(int32_t request_id, |
| + int32_t count, |
| + bool final_update) override { |
| + find_count_ = count; |
| + if (final_update && quit_condition_ == FINAL_FIND_UPATE) |
| + QuitNestedRunLoop(); |
| + } |
| + void ReportFindInPageSelection(int32_t request_id, |
| + int32_t active_match_ordinal) override { |
| + active_find_match_ = active_match_ordinal; |
| + } |
| mojo::ApplicationImpl* app_; |
| @@ -127,6 +157,11 @@ class WebViewTest : public mus::ViewManagerTestBase, |
| mojom::ButtonState last_back_button_state_; |
| mojom::ButtonState last_forward_button_state_; |
| + NestedLoopQuitCondition quit_condition_; |
| + |
| + int32_t active_find_match_; |
| + int32_t find_count_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(WebViewTest); |
| }; |
| @@ -157,7 +192,7 @@ TEST_F(WebViewTest, CanGoBackAndForward) { |
| last_forward_button_state()); |
| web_view()->GoBack(); |
| - StartNestedRunLoopUntilLoadingDone(); |
| + StartNestedRunLoopUntil(LOADING_DONE); |
| EXPECT_EQ(GetTestFileURL(kTestOneFile).spec(), navigation_url()); |
| EXPECT_EQ(kTestOneTitle, last_title()); |
| @@ -167,7 +202,7 @@ TEST_F(WebViewTest, CanGoBackAndForward) { |
| last_forward_button_state()); |
| web_view()->GoForward(); |
| - StartNestedRunLoopUntilLoadingDone(); |
| + StartNestedRunLoopUntil(LOADING_DONE); |
| EXPECT_EQ(GetTestFileURL(kTestTwoFile).spec(), navigation_url()); |
| EXPECT_EQ(kTestTwoTitle, last_title()); |
| EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_ENABLED, last_back_button_state()); |
| @@ -182,7 +217,7 @@ TEST_F(WebViewTest, NavigationClearsForward) { |
| ASSERT_NO_FATAL_FAILURE(NavigateTo(kTestTwoFile)); |
| web_view()->GoBack(); |
| - StartNestedRunLoopUntilLoadingDone(); |
| + StartNestedRunLoopUntil(LOADING_DONE); |
| EXPECT_EQ(GetTestFileURL(kTestOneFile).spec(), navigation_url()); |
| EXPECT_EQ(kTestOneTitle, last_title()); |
| @@ -201,4 +236,22 @@ TEST_F(WebViewTest, NavigationClearsForward) { |
| last_forward_button_state()); |
| } |
| +TEST_F(WebViewTest, Find) { |
| + ASSERT_NO_FATAL_FAILURE(NavigateTo(kTheWordGreenFiveTimes)); |
| + |
| + web_view()->Find(1, "Green"); |
| + StartNestedRunLoopUntil(FINAL_FIND_UPATE); |
| + EXPECT_EQ(1, active_find_match()); |
| + EXPECT_EQ(5, find_count()); |
| +} |
| + |
| +TEST_F(WebViewTest, FindAcrossIframes) { |
| + ASSERT_NO_FATAL_FAILURE(NavigateTo(kTwoIframesWithGreen)); |
| + |
| + web_view()->Find(1, "Green"); |
| + StartNestedRunLoopUntil(FINAL_FIND_UPATE); |
| + EXPECT_EQ(13, find_count()); |
| +} |
| + |
|
sky
2015/10/02 16:03:40
nit: only one newline.
|
| + |
| } // namespace web_view |