OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <queue> | 5 #include <queue> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 content::WebContentsDelegate* orig_delegate_; | 348 content::WebContentsDelegate* orig_delegate_; |
349 bool waiting_for_decision_; | 349 bool waiting_for_decision_; |
350 bool expect_allow_; | 350 bool expect_allow_; |
351 bool decision_made_; | 351 bool decision_made_; |
352 bool last_download_allowed_; | 352 bool last_download_allowed_; |
353 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 353 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
354 | 354 |
355 DISALLOW_COPY_AND_ASSIGN(MockDownloadWebContentsDelegate); | 355 DISALLOW_COPY_AND_ASSIGN(MockDownloadWebContentsDelegate); |
356 }; | 356 }; |
357 | 357 |
| 358 class TextInputStateHelper { |
| 359 public: |
| 360 using Predicate = |
| 361 base::Callback<bool(const content::TextInputStateTestExport&)>; |
| 362 |
| 363 static void WaitForDesiredState(content::WebContents* web_contents, |
| 364 const Predicate& predicate) { |
| 365 content::TextInputStateTestExport state = |
| 366 content::TextInputStateTestExport::FromWebContents(web_contents); |
| 367 while (!predicate.Run(state)) { |
| 368 scoped_refptr<content::MessageLoopRunner> loop = |
| 369 new content::MessageLoopRunner(); |
| 370 content::BrowserThread::PostDelayedTask( |
| 371 content::BrowserThread::UI, FROM_HERE, loop->QuitClosure(), |
| 372 base::TimeDelta::FromMilliseconds(1LL)); |
| 373 loop->Run(); |
| 374 state = content::TextInputStateTestExport::FromWebContents(web_contents); |
| 375 } |
| 376 } |
| 377 |
| 378 static bool IsStateOfGivenType( |
| 379 ui::TextInputType type, |
| 380 const content::TextInputStateTestExport& state) { |
| 381 return type == state.type(); |
| 382 } |
| 383 |
| 384 static bool HasGivenValue(const std::string& value, |
| 385 const content::TextInputStateTestExport& state) { |
| 386 return value == state.value(); |
| 387 } |
| 388 }; |
| 389 |
358 // TODO(wjmaclean): Fix this test class at some point so it can be re-enabled on | 390 // TODO(wjmaclean): Fix this test class at some point so it can be re-enabled on |
359 // the site isolation bots, and then look at re-enabling WebViewFocusTest when | 391 // the site isolation bots, and then look at re-enabling WebViewFocusTest when |
360 // that happens. | 392 // that happens. |
361 // https://crbug.com/503751 | 393 // https://crbug.com/503751 |
362 class WebViewTestBase : public extensions::PlatformAppBrowserTest { | 394 class WebViewTestBase : public extensions::PlatformAppBrowserTest { |
363 protected: | 395 protected: |
364 void SetUp() override { | 396 void SetUp() override { |
365 if (UsesFakeSpeech()) { | 397 if (UsesFakeSpeech()) { |
366 // SpeechRecognition test specific SetUp. | 398 // SpeechRecognition test specific SetUp. |
367 fake_speech_recognition_manager_.reset( | 399 fake_speech_recognition_manager_.reset( |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 void SetUpCommandLine(base::CommandLine* command_line) override { | 808 void SetUpCommandLine(base::CommandLine* command_line) override { |
777 WebViewTest::SetUpCommandLine(command_line); | 809 WebViewTest::SetUpCommandLine(command_line); |
778 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor, | 810 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor, |
779 base::StringPrintf("%f", scale())); | 811 base::StringPrintf("%f", scale())); |
780 command_line->AppendSwitch(switches::kEnableUseZoomForDSF); | 812 command_line->AppendSwitch(switches::kEnableUseZoomForDSF); |
781 } | 813 } |
782 | 814 |
783 static float scale() { return 2.0f; } | 815 static float scale() { return 2.0f; } |
784 }; | 816 }; |
785 | 817 |
| 818 // TODO(ekaramad): Enable this test for OOPIF. |
| 819 class WebViewTextInputStateTest : public WebViewTest {}; |
| 820 INSTANTIATE_TEST_CASE_P(WebViewTests, |
| 821 WebViewTextInputStateTest, |
| 822 testing::Bool()); |
| 823 |
786 class WebContentsAudioMutedObserver : public content::WebContentsObserver { | 824 class WebContentsAudioMutedObserver : public content::WebContentsObserver { |
787 public: | 825 public: |
788 explicit WebContentsAudioMutedObserver(content::WebContents* web_contents) | 826 explicit WebContentsAudioMutedObserver(content::WebContents* web_contents) |
789 : WebContentsObserver(web_contents), | 827 : WebContentsObserver(web_contents), |
790 loop_runner_(new content::MessageLoopRunner), | 828 loop_runner_(new content::MessageLoopRunner), |
791 muting_update_observed_(false) {} | 829 muting_update_observed_(false) {} |
792 | 830 |
793 // WebContentsObserver. | 831 // WebContentsObserver. |
794 void DidUpdateAudioMutingState(bool muted) override { | 832 void DidUpdateAudioMutingState(bool muted) override { |
795 muting_update_observed_ = true; | 833 muting_update_observed_ = true; |
(...skipping 2310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3106 // 4 tasks expected. The order is arbitrary. | 3144 // 4 tasks expected. The order is arbitrary. |
3107 // Tab: about:blank, | 3145 // Tab: about:blank, |
3108 // Background Page: <webview> task manager test, | 3146 // Background Page: <webview> task manager test, |
3109 // App: <webview> task manager test, | 3147 // App: <webview> task manager test, |
3110 // Webview: WebViewed test content. | 3148 // Webview: WebViewed test content. |
3111 EXPECT_EQ(4U, task_manager.tasks().size()); | 3149 EXPECT_EQ(4U, task_manager.tasks().size()); |
3112 EXPECT_TRUE(HasExpectedGuestTask(task_manager, guest_contents)); | 3150 EXPECT_TRUE(HasExpectedGuestTask(task_manager, guest_contents)); |
3113 } | 3151 } |
3114 | 3152 |
3115 #endif // defined(ENABLE_TASK_MANAGER) | 3153 #endif // defined(ENABLE_TASK_MANAGER) |
| 3154 |
| 3155 // TODO(ekaramad): Activate this test for OOPIF when input event routing for |
| 3156 // OOPIF-<webview> is fixed. |
| 3157 IN_PROC_BROWSER_TEST_P(WebViewTextInputStateTest, |
| 3158 TopLevelWebContentsTracksCorrectly) { |
| 3159 if (content::BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) |
| 3160 return; |
| 3161 |
| 3162 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 3163 |
| 3164 EXPECT_TRUE(!!LoadGuest( |
| 3165 "/extensions/platform_apps/web_view/text_input_state/guest.html", |
| 3166 "web_view/text_input_state")); |
| 3167 |
| 3168 auto press_tab = [](content::WebContents* web_contents) { |
| 3169 content::SimulateKeyPress(web_contents, ui::VKEY_TAB, false, false, false, |
| 3170 false); |
| 3171 }; |
| 3172 |
| 3173 auto get_type_checker = [](ui::TextInputType target) { |
| 3174 return base::Bind(&TextInputStateHelper::IsStateOfGivenType, target); |
| 3175 }; |
| 3176 |
| 3177 content::WebContents* embedder_webcontents = GetEmbedderWebContents(); |
| 3178 |
| 3179 // Press the tab key. The <input> in the embedder should get focused. |
| 3180 // Top level state type should be number. |
| 3181 press_tab(embedder_webcontents); |
| 3182 TextInputStateHelper::WaitForDesiredState( |
| 3183 GetEmbedderWebContents(), get_type_checker(ui::TEXT_INPUT_TYPE_NUMBER)); |
| 3184 |
| 3185 // Press the tab key again and the <input> inside <webview> gets focused. The |
| 3186 // input type should text now. |
| 3187 press_tab(embedder_webcontents); |
| 3188 TextInputStateHelper::WaitForDesiredState( |
| 3189 GetEmbedderWebContents(), get_type_checker(ui::TEXT_INPUT_TYPE_TEXT)); |
| 3190 |
| 3191 // Press the tab key one more time to get back to embedder's second <input>. |
| 3192 // The value should be "last one". |
| 3193 press_tab(embedder_webcontents); |
| 3194 TextInputStateHelper::WaitForDesiredState( |
| 3195 GetEmbedderWebContents(), |
| 3196 base::Bind(&TextInputStateHelper::HasGivenValue, "last one")); |
| 3197 } |
| 3198 |
| 3199 // TODO(ekaramad): Activate this test for OOPIF when input event routing for |
| 3200 // OOPIF-<webview> is fixed. |
| 3201 IN_PROC_BROWSER_TEST_P(WebViewTextInputStateTest, CrashingWebViewResetsState) { |
| 3202 if (content::BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) |
| 3203 return; |
| 3204 |
| 3205 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 3206 |
| 3207 content::WebContents* guest_contents = LoadGuest( |
| 3208 "/extensions/platform_apps/web_view/text_input_state/guest.html", |
| 3209 "web_view/text_input_state"); |
| 3210 |
| 3211 // Press tab key twice to end up in the <input> of the <webview>, |
| 3212 for (size_t i = 0; i < 2; ++i) { |
| 3213 content::SimulateKeyPress(GetEmbedderWebContents(), ui::VKEY_TAB, false, |
| 3214 false, false, false); |
| 3215 }; |
| 3216 |
| 3217 TextInputStateHelper::WaitForDesiredState( |
| 3218 GetEmbedderWebContents(), |
| 3219 base::Bind(&TextInputStateHelper::HasGivenValue, "guest")); |
| 3220 |
| 3221 // Now crash the <webview>. |
| 3222 guest_contents->GetRenderProcessHost()->Shutdown(false, 0); |
| 3223 |
| 3224 // State should reset to none. |
| 3225 TextInputStateHelper::WaitForDesiredState( |
| 3226 GetEmbedderWebContents(), |
| 3227 base::Bind(&TextInputStateHelper::IsStateOfGivenType, |
| 3228 ui::TEXT_INPUT_TYPE_NONE)); |
| 3229 } |
OLD | NEW |