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

Side by Side Diff: chrome/browser/apps/guest_view/web_view_browsertest.cc

Issue 1652483002: Browser Side Text Input State Tracking for OOPIF. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 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
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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 void SetUpCommandLine(base::CommandLine* command_line) override { 806 void SetUpCommandLine(base::CommandLine* command_line) override {
775 WebViewTest::SetUpCommandLine(command_line); 807 WebViewTest::SetUpCommandLine(command_line);
776 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor, 808 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor,
777 base::StringPrintf("%f", scale())); 809 base::StringPrintf("%f", scale()));
778 command_line->AppendSwitch(switches::kEnableUseZoomForDSF); 810 command_line->AppendSwitch(switches::kEnableUseZoomForDSF);
779 } 811 }
780 812
781 static float scale() { return 2.0f; } 813 static float scale() { return 2.0f; }
782 }; 814 };
783 815
816 // TODO(ekaramad): Enable this test for OOPIF.
817 class WebViewTextInputStateTest : public WebViewTest {};
818 INSTANTIATE_TEST_CASE_P(WebViewTests,
819 WebViewTextInputStateTest,
820 testing::Bool());
821
784 class WebContentsAudioMutedObserver : public content::WebContentsObserver { 822 class WebContentsAudioMutedObserver : public content::WebContentsObserver {
785 public: 823 public:
786 explicit WebContentsAudioMutedObserver(content::WebContents* web_contents) 824 explicit WebContentsAudioMutedObserver(content::WebContents* web_contents)
787 : WebContentsObserver(web_contents), 825 : WebContentsObserver(web_contents),
788 loop_runner_(new content::MessageLoopRunner), 826 loop_runner_(new content::MessageLoopRunner),
789 muting_update_observed_(false) {} 827 muting_update_observed_(false) {}
790 828
791 // WebContentsObserver. 829 // WebContentsObserver.
792 void DidUpdateAudioMutingState(bool muted) override { 830 void DidUpdateAudioMutingState(bool muted) override {
793 muting_update_observed_ = true; 831 muting_update_observed_ = true;
(...skipping 2315 matching lines...) Expand 10 before | Expand all | Expand 10 after
3109 // 4 tasks expected. The order is arbitrary. 3147 // 4 tasks expected. The order is arbitrary.
3110 // Tab: about:blank, 3148 // Tab: about:blank,
3111 // Background Page: <webview> task manager test, 3149 // Background Page: <webview> task manager test,
3112 // App: <webview> task manager test, 3150 // App: <webview> task manager test,
3113 // Webview: WebViewed test content. 3151 // Webview: WebViewed test content.
3114 EXPECT_EQ(4U, task_manager.tasks().size()); 3152 EXPECT_EQ(4U, task_manager.tasks().size());
3115 EXPECT_TRUE(HasExpectedGuestTask(task_manager, guest_contents)); 3153 EXPECT_TRUE(HasExpectedGuestTask(task_manager, guest_contents));
3116 } 3154 }
3117 3155
3118 #endif // defined(ENABLE_TASK_MANAGER) 3156 #endif // defined(ENABLE_TASK_MANAGER)
3157
3158 // TODO(ekaramad): Activate this test for OOPIF when input event routing for
3159 // OOPIF-<webview> is fixed.
3160 IN_PROC_BROWSER_TEST_P(WebViewTextInputStateTest,
3161 TopLevelWebContentsTracksCorrectly) {
3162 if (content::BrowserPluginGuestMode::UseCrossProcessFramesForGuests())
3163 return;
3164
3165 ASSERT_TRUE(StartEmbeddedTestServer());
3166
3167 EXPECT_TRUE(!!LoadGuest(
3168 "/extensions/platform_apps/web_view/text_input_state/guest.html",
3169 "web_view/text_input_state"));
3170
3171 auto press_tab = [](content::WebContents* web_contents) {
3172 content::SimulateKeyPress(web_contents, ui::VKEY_TAB, false, false, false,
3173 false);
3174 };
3175
3176 auto get_type_checker = [](ui::TextInputType target) {
3177 return base::Bind(&TextInputStateHelper::IsStateOfGivenType, target);
3178 };
3179
3180 content::WebContents* embedder_webcontents = GetEmbedderWebContents();
3181
3182 // Press the tab key. The <input> in the embedder should get focused.
3183 // Top level state type should be number.
3184 press_tab(embedder_webcontents);
3185 TextInputStateHelper::WaitForDesiredState(
lazyboy 2016/04/04 19:17:59 Generally, queuing tasks to wait for a change is d
EhsanK 2016/04/06 00:37:58 (As discussed offline) I now listen to 'onfocus()'
3186 GetEmbedderWebContents(), get_type_checker(ui::TEXT_INPUT_TYPE_NUMBER));
3187
3188 // Press the tab key again and the <input> inside <webview> gets focused. The
3189 // input type should text now.
3190 press_tab(embedder_webcontents);
3191 TextInputStateHelper::WaitForDesiredState(
3192 GetEmbedderWebContents(), get_type_checker(ui::TEXT_INPUT_TYPE_TEXT));
3193
3194 // Press the tab key one more time to get back to embedder's second <input>.
3195 // The value should be "last one".
3196 press_tab(embedder_webcontents);
3197 TextInputStateHelper::WaitForDesiredState(
3198 GetEmbedderWebContents(),
3199 base::Bind(&TextInputStateHelper::HasGivenValue, "last one"));
3200 }
3201
3202 // TODO(ekaramad): Activate this test for OOPIF when input event routing for
3203 // OOPIF-<webview> is fixed.
3204 IN_PROC_BROWSER_TEST_P(WebViewTextInputStateTest, CrashingWebViewResetsState) {
3205 if (content::BrowserPluginGuestMode::UseCrossProcessFramesForGuests())
3206 return;
3207
3208 ASSERT_TRUE(StartEmbeddedTestServer());
3209
3210 content::WebContents* guest_contents = LoadGuest(
3211 "/extensions/platform_apps/web_view/text_input_state/guest.html",
3212 "web_view/text_input_state");
3213
3214 // Press tab key twice to end up in the <input> of the <webview>,
3215 for (size_t i = 0; i < 2; ++i) {
3216 content::SimulateKeyPress(GetEmbedderWebContents(), ui::VKEY_TAB, false,
3217 false, false, false);
3218 };
3219
3220 TextInputStateHelper::WaitForDesiredState(
3221 GetEmbedderWebContents(),
3222 base::Bind(&TextInputStateHelper::HasGivenValue, "guest"));
3223
3224 // Now crash the <webview>.
3225 guest_contents->GetRenderProcessHost()->Shutdown(false, 0);
3226
3227 // State should reset to none.
3228 TextInputStateHelper::WaitForDesiredState(
3229 GetEmbedderWebContents(),
3230 base::Bind(&TextInputStateHelper::IsStateOfGivenType,
3231 ui::TEXT_INPUT_TYPE_NONE));
3232 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698