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

Side by Side Diff: chrome/browser/plugins/flash_permission_browsertest.cc

Issue 2540683002: Don't defer quitting in ExecuteScript and other helpers that use DOMMessageQueue. (Closed)
Patch Set: Spin the loop in PRE_CreateAndCancelSupervisedUser. Created 4 years 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/base_switches.h" 5 #include "base/base_switches.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "chrome/browser/permissions/permissions_browsertest.h" 8 #include "chrome/browser/permissions/permissions_browsertest.h"
9 #include "chrome/browser/ui/website_settings/mock_permission_prompt_factory.h" 9 #include "chrome/browser/ui/website_settings/mock_permission_prompt_factory.h"
10 #include "chrome/common/chrome_paths.h" 10 #include "chrome/common/chrome_paths.h"
11 #include "chrome/test/base/ui_test_utils.h" 11 #include "chrome/test/base/ui_test_utils.h"
12 #include "components/variations/variations_switches.h" 12 #include "components/variations/variations_switches.h"
13 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
14 #include "content/public/common/content_switches.h" 14 #include "content/public/common/content_switches.h"
15 #include "content/public/test/browser_test_utils.h" 15 #include "content/public/test/browser_test_utils.h"
16 #include "content/public/test/ppapi_test_utils.h" 16 #include "content/public/test/ppapi_test_utils.h"
17 #include "third_party/WebKit/public/platform/WebInputEvent.h" 17 #include "third_party/WebKit/public/platform/WebInputEvent.h"
18 #include "url/gurl.h" 18 #include "url/gurl.h"
19 19
20 namespace {
21
22 class PageReloadWaiter {
nasko 2016/11/30 17:38:56 Why do we need this wrapper for TestNavigationMana
Alexander Semashko 2016/11/30 22:23:08 Yes, waiting only for commit here seems wrong. Tes
nasko 2016/12/01 01:17:28 Maybe UrlLoadObserver then fits the picture better
Alexander Semashko 2016/12/01 12:24:59 Unfortunately, no. When an intermediate navigation
nasko 2016/12/01 17:23:09 : ( Is the intermediate navigation in the same fra
23 public:
24 explicit PageReloadWaiter(content::WebContents* web_contents)
25 : web_contents_(web_contents),
26 navigation_observer_(web_contents,
27 web_contents->GetLastCommittedURL()) {}
28
29 void Wait() {
30 navigation_observer_.WaitForNavigationFinished();
31 EXPECT_TRUE(content::WaitForLoadStop(web_contents_));
32 }
33
34 private:
35 content::WebContents* web_contents_;
36 content::TestNavigationManager navigation_observer_;
37 };
38
39 } // namespace
40
20 class FlashPermissionBrowserTest : public PermissionsBrowserTest { 41 class FlashPermissionBrowserTest : public PermissionsBrowserTest {
21 public: 42 public:
22 FlashPermissionBrowserTest() 43 FlashPermissionBrowserTest()
23 : PermissionsBrowserTest("/permissions/flash.html") {} 44 : PermissionsBrowserTest("/permissions/flash.html") {}
24 ~FlashPermissionBrowserTest() override {} 45 ~FlashPermissionBrowserTest() override {}
25 46
26 // PermissionsBrowserTest 47 // PermissionsBrowserTest
27 void SetUpCommandLine(base::CommandLine* command_line) override { 48 void SetUpCommandLine(base::CommandLine* command_line) override {
28 PermissionsBrowserTest::SetUpCommandLine(command_line); 49 PermissionsBrowserTest::SetUpCommandLine(command_line);
29 50
30 ASSERT_TRUE(ppapi::RegisterFlashTestPlugin(command_line)); 51 ASSERT_TRUE(ppapi::RegisterFlashTestPlugin(command_line));
31 52
32 // Set a high engagement threshhold so it doesn't interfere with testing the 53 // Set a high engagement threshhold so it doesn't interfere with testing the
33 // permission. 54 // permission.
34 command_line->AppendSwitchASCII(switches::kEnableFeatures, 55 command_line->AppendSwitchASCII(switches::kEnableFeatures,
35 "PreferHtmlOverPlugins<Study1"); 56 "PreferHtmlOverPlugins<Study1");
36 command_line->AppendSwitchASCII(switches::kForceFieldTrials, 57 command_line->AppendSwitchASCII(switches::kForceFieldTrials,
37 "Study1/Enabled/"); 58 "Study1/Enabled/");
38 command_line->AppendSwitchASCII( 59 command_line->AppendSwitchASCII(
39 variations::switches::kForceFieldTrialParams, 60 variations::switches::kForceFieldTrialParams,
40 "Study1.Enabled:engagement_threshold_for_flash/100"); 61 "Study1.Enabled:engagement_threshold_for_flash/100");
41 } 62 }
42 63
43 void TriggerPrompt() override { 64 void TriggerPrompt() override {
44 if (prompt_factory()->response_type() == 65 if (prompt_factory()->response_type() ==
45 PermissionRequestManager::ACCEPT_ALL) { 66 PermissionRequestManager::ACCEPT_ALL) {
46 // If the prompt will be allowed, we need to wait for the page to refresh. 67 // If the prompt will be allowed, we need to wait for the page to refresh.
47 content::TestNavigationManager observer( 68 PageReloadWaiter reload_waiter(GetWebContents());
48 GetWebContents(), GetWebContents()->GetLastCommittedURL());
49 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();")); 69 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();"));
50 observer.WaitForNavigationFinished(); 70 reload_waiter.Wait();
51 } else { 71 } else {
52 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();")); 72 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();"));
53 } 73 }
54 } 74 }
55 75
56 bool FeatureUsageSucceeds() override { 76 bool FeatureUsageSucceeds() override {
57 // Wait until the page is refreshed before testing whether flash is enabled
58 // or disabled.
59 ui_test_utils::NavigateToURL(browser(),
Alexander Semashko 2016/11/30 22:23:08 Just for the information. This was an "extra" navi
60 GetWebContents()->GetLastCommittedURL());
61 // If either flash with or without fallback content runs successfully it 77 // If either flash with or without fallback content runs successfully it
62 // indicates the feature is at least partly working, which could imply a 78 // indicates the feature is at least partly working, which could imply a
63 // faulty permission. 79 // faulty permission.
64 return RunScriptReturnBool("flashIsEnabled();") || 80 return RunScriptReturnBool("flashIsEnabled();") ||
65 RunScriptReturnBool("flashIsEnabledForPluginWithoutFallback();"); 81 RunScriptReturnBool("flashIsEnabledForPluginWithoutFallback();");
66 } 82 }
67 }; 83 };
68 84
69 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, 85 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest,
70 CommonFailsBeforeRequesting) { 86 CommonFailsBeforeRequesting) {
71 CommonFailsBeforeRequesting(); 87 CommonFailsBeforeRequesting();
72 } 88 }
73 89
74 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonFailsIfDismissed) { 90 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonFailsIfDismissed) {
75 CommonFailsIfDismissed(); 91 CommonFailsIfDismissed();
76 } 92 }
77 93
78 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonFailsIfBlocked) { 94 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonFailsIfBlocked) {
79 CommonFailsIfBlocked(); 95 CommonFailsIfBlocked();
80 } 96 }
81 97
82 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonSucceedsIfAllowed) { 98 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonSucceedsIfAllowed) {
83 CommonSucceedsIfAllowed(); 99 CommonSucceedsIfAllowed();
84 } 100 }
85 101
86 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, TriggerPromptViaNewWindow) { 102 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, TriggerPromptViaNewWindow) {
87 EXPECT_EQ(0, prompt_factory()->total_request_count()); 103 EXPECT_EQ(0, prompt_factory()->total_request_count());
88 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); 104 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL);
105 // FlashPermissionContext::UpdateTabContext will reload the page, we'll have
106 // to wait until it is ready.
107 PageReloadWaiter reload_waiter(GetWebContents());
89 EXPECT_TRUE(RunScriptReturnBool("triggerPromptViaNewWindow();")); 108 EXPECT_TRUE(RunScriptReturnBool("triggerPromptViaNewWindow();"));
109 reload_waiter.Wait();
90 110
91 EXPECT_TRUE(FeatureUsageSucceeds()); 111 EXPECT_TRUE(FeatureUsageSucceeds());
92 EXPECT_EQ(1, prompt_factory()->total_request_count()); 112 EXPECT_EQ(1, prompt_factory()->total_request_count());
93 } 113 }
94 114
95 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, 115 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest,
96 TriggerPromptViaPluginPlaceholder) { 116 TriggerPromptViaPluginPlaceholder) {
97 EXPECT_EQ(0, prompt_factory()->total_request_count()); 117 EXPECT_EQ(0, prompt_factory()->total_request_count());
98 EXPECT_FALSE(FeatureUsageSucceeds()); 118 EXPECT_FALSE(FeatureUsageSucceeds());
99 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); 119 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL);
100 // We need to simulate a mouse click to trigger the placeholder to prompt. 120 // We need to simulate a mouse click to trigger the placeholder to prompt.
101 content::TestNavigationManager observer( 121 // When the prompt is auto-accepted, the page will be reloaded.
102 GetWebContents(), GetWebContents()->GetLastCommittedURL()); 122 PageReloadWaiter reload_waiter(GetWebContents());
103 content::SimulateMouseClickAt(GetWebContents(), 0 /* modifiers */, 123 content::SimulateMouseClickAt(GetWebContents(), 0 /* modifiers */,
104 blink::WebMouseEvent::Button::Left, 124 blink::WebMouseEvent::Button::Left,
105 gfx::Point(50, 50)); 125 gfx::Point(50, 50));
106 observer.WaitForNavigationFinished(); 126 reload_waiter.Wait();
107 127
108 EXPECT_TRUE(FeatureUsageSucceeds()); 128 EXPECT_TRUE(FeatureUsageSucceeds());
109 EXPECT_EQ(1, prompt_factory()->total_request_count()); 129 EXPECT_EQ(1, prompt_factory()->total_request_count());
110 } 130 }
111 131
112 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, AllowFileURL) { 132 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, AllowFileURL) {
113 base::FilePath test_path; 133 base::FilePath test_path;
114 PathService::Get(chrome::DIR_TEST_DATA, &test_path); 134 PathService::Get(chrome::DIR_TEST_DATA, &test_path);
115 ui_test_utils::NavigateToURL( 135 ui_test_utils::NavigateToURL(
116 browser(), GURL("file://" + test_path.AsUTF8Unsafe() + test_url())); 136 browser(), GURL("file://" + test_path.AsUTF8Unsafe() + test_url()));
(...skipping 14 matching lines...) Expand all
131 browser(), GURL("file://" + test_path.AsUTF8Unsafe() + test_url())); 151 browser(), GURL("file://" + test_path.AsUTF8Unsafe() + test_url()));
132 CommonFailsIfBlocked(); 152 CommonFailsIfBlocked();
133 EXPECT_EQ(1, prompt_factory()->total_request_count()); 153 EXPECT_EQ(1, prompt_factory()->total_request_count());
134 154
135 // Navigate to a second URL to verify it's blocked on all file: URLs. 155 // Navigate to a second URL to verify it's blocked on all file: URLs.
136 ui_test_utils::NavigateToURL( 156 ui_test_utils::NavigateToURL(
137 browser(), 157 browser(),
138 GURL("file://" + test_path.AsUTF8Unsafe() + "/permissions/flash2.html")); 158 GURL("file://" + test_path.AsUTF8Unsafe() + "/permissions/flash2.html"));
139 EXPECT_FALSE(FeatureUsageSucceeds()); 159 EXPECT_FALSE(FeatureUsageSucceeds());
140 } 160 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698