OLD | NEW |
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/test/scoped_feature_list.h" | 5 #include "base/test/scoped_feature_list.h" |
6 #include "chrome/browser/engagement/site_engagement_score.h" | 6 #include "chrome/browser/engagement/site_engagement_score.h" |
7 #include "chrome/browser/permissions/permissions_browsertest.h" | 7 #include "chrome/browser/permissions/permissions_browsertest.h" |
8 #include "chrome/browser/ui/website_settings/mock_permission_prompt_factory.h" | 8 #include "chrome/browser/ui/website_settings/mock_permission_prompt_factory.h" |
9 #include "chrome/common/chrome_features.h" | 9 #include "chrome/common/chrome_features.h" |
10 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
11 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 12 #include "content/public/test/browser_test_utils.h" |
12 #include "content/public/test/ppapi_test_utils.h" | 13 #include "content/public/test/ppapi_test_utils.h" |
| 14 #include "third_party/WebKit/public/web/WebInputEvent.h" |
13 | 15 |
14 class FlashPermissionBrowserTest : public PermissionsBrowserTest { | 16 class FlashPermissionBrowserTest : public PermissionsBrowserTest { |
15 public: | 17 public: |
16 FlashPermissionBrowserTest() | 18 FlashPermissionBrowserTest() |
17 : PermissionsBrowserTest("/permissions/flash.html") {} | 19 : PermissionsBrowserTest("/permissions/flash.html") {} |
18 ~FlashPermissionBrowserTest() override {} | 20 ~FlashPermissionBrowserTest() override {} |
19 | 21 |
20 // PermissionsBrowserTest | 22 // PermissionsBrowserTest |
21 void SetUpCommandLine(base::CommandLine* command_line) override { | 23 void SetUpCommandLine(base::CommandLine* command_line) override { |
22 PermissionsBrowserTest::SetUpCommandLine(command_line); | 24 PermissionsBrowserTest::SetUpCommandLine(command_line); |
23 ASSERT_TRUE(ppapi::RegisterFlashTestPlugin(command_line)); | 25 ASSERT_TRUE(ppapi::RegisterFlashTestPlugin(command_line)); |
24 | 26 |
25 feature_list_.InitAndEnableFeature(features::kPreferHtmlOverPlugins); | 27 feature_list_.InitAndEnableFeature(features::kPreferHtmlOverPlugins); |
26 } | 28 } |
27 | 29 |
28 void SetUpOnMainThread() override { | 30 void SetUpOnMainThread() override { |
29 SiteEngagementScore::SetParamValuesForTesting(); | 31 SiteEngagementScore::SetParamValuesForTesting(); |
30 | 32 |
31 PermissionsBrowserTest::SetUpOnMainThread(); | 33 PermissionsBrowserTest::SetUpOnMainThread(); |
32 } | 34 } |
33 void TriggerPrompt() override { | 35 void TriggerPrompt() override { |
34 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();")); | 36 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();")); |
35 } | 37 } |
36 bool FeatureUsageSucceeds() override { | 38 bool FeatureUsageSucceeds() override { |
37 // Flash won't be enabled until the page is refreshed. | 39 // Flash won't be enabled until the page is refreshed. |
38 ui_test_utils::NavigateToURL(browser(), | 40 ui_test_utils::NavigateToURL(browser(), |
39 GetWebContents()->GetLastCommittedURL()); | 41 GetWebContents()->GetLastCommittedURL()); |
40 return RunScriptReturnBool("flashIsEnabled();"); | 42 // If either flash with or without fallback content runs successfully it |
| 43 // indicates the feature is at least partly working, which could imply a |
| 44 // faulty permission. |
| 45 return RunScriptReturnBool("flashIsEnabled();") || |
| 46 RunScriptReturnBool("flashIsEnabledForPluginWithoutFallack();"); |
41 } | 47 } |
42 | 48 |
43 base::test::ScopedFeatureList feature_list_; | 49 base::test::ScopedFeatureList feature_list_; |
44 }; | 50 }; |
45 | 51 |
46 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, | 52 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, |
47 CommonFailsBeforeRequesting) { | 53 CommonFailsBeforeRequesting) { |
48 CommonFailsBeforeRequesting(); | 54 CommonFailsBeforeRequesting(); |
49 } | 55 } |
50 | 56 |
(...skipping 10 matching lines...) Expand all Loading... |
61 } | 67 } |
62 | 68 |
63 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, TriggerPromptViaNewWindow) { | 69 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, TriggerPromptViaNewWindow) { |
64 EXPECT_EQ(0, prompt_factory()->total_request_count()); | 70 EXPECT_EQ(0, prompt_factory()->total_request_count()); |
65 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); | 71 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
66 EXPECT_TRUE(RunScriptReturnBool("triggerPromptViaNewWindow();")); | 72 EXPECT_TRUE(RunScriptReturnBool("triggerPromptViaNewWindow();")); |
67 | 73 |
68 EXPECT_EQ(1, prompt_factory()->total_request_count()); | 74 EXPECT_EQ(1, prompt_factory()->total_request_count()); |
69 EXPECT_TRUE(FeatureUsageSucceeds()); | 75 EXPECT_TRUE(FeatureUsageSucceeds()); |
70 } | 76 } |
| 77 |
| 78 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, |
| 79 TriggerPromptViaPluginPlaceholder) { |
| 80 EXPECT_EQ(0, prompt_factory()->total_request_count()); |
| 81 EXPECT_FALSE(FeatureUsageSucceeds()); |
| 82 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| 83 // We need to simulate a mouse click to trigger the placeholder to prompt. |
| 84 content::SimulateMouseClickAt(GetWebContents(), 0 /* modifiers */, |
| 85 blink::WebMouseEvent::Button::Left, |
| 86 gfx::Point(50, 50)); |
| 87 EXPECT_TRUE(FeatureUsageSucceeds()); |
| 88 |
| 89 EXPECT_EQ(1, prompt_factory()->total_request_count()); |
| 90 } |
OLD | NEW |