| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/permissions/permissions_browsertest.h" |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/permissions/permission_request_manager.h" |
| 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 11 #include "chrome/browser/ui/website_settings/mock_permission_prompt_factory.h" |
| 12 #include "chrome/test/base/ui_test_utils.h" |
| 13 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/test/browser_test_utils.h" |
| 15 #include "content/public/test/test_utils.h" |
| 16 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 17 |
| 18 PermissionsBrowserTest::PermissionsBrowserTest(const std::string& test_url) |
| 19 : test_url_(test_url) {} |
| 20 |
| 21 PermissionsBrowserTest::~PermissionsBrowserTest() {} |
| 22 |
| 23 void PermissionsBrowserTest::SetUpOnMainThread() { |
| 24 InProcessBrowserTest::SetUpOnMainThread(); |
| 25 |
| 26 PermissionRequestManager* manager = PermissionRequestManager::FromWebContents( |
| 27 browser()->tab_strip_model()->GetActiveWebContents()); |
| 28 prompt_factory_.reset(new MockPermissionPromptFactory(manager)); |
| 29 manager->DisplayPendingRequests(); |
| 30 |
| 31 ASSERT_TRUE(embedded_test_server()->Start()); |
| 32 |
| 33 ui_test_utils::NavigateToURL(browser(), |
| 34 embedded_test_server()->GetURL(test_url())); |
| 35 } |
| 36 |
| 37 void PermissionsBrowserTest::TearDownOnMainThread() { |
| 38 prompt_factory_.reset(); |
| 39 |
| 40 InProcessBrowserTest::TearDownOnMainThread(); |
| 41 } |
| 42 |
| 43 bool PermissionsBrowserTest::RunScriptReturnBool(const std::string& script) { |
| 44 bool result; |
| 45 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 46 GetWebContents()->GetMainFrame(), script, &result)); |
| 47 return result; |
| 48 } |
| 49 |
| 50 content::WebContents* PermissionsBrowserTest::GetWebContents() { |
| 51 return browser()->tab_strip_model()->GetActiveWebContents(); |
| 52 } |
| 53 |
| 54 void PermissionsBrowserTest::CommonFailsBeforeRequesting() { |
| 55 EXPECT_EQ(0, prompt_factory()->total_request_count()); |
| 56 // Dismiss any prompts if they are shown when using the feature. |
| 57 prompt_factory()->set_response_type(PermissionRequestManager::DISMISS); |
| 58 EXPECT_FALSE(FeatureUsageSucceeds()); |
| 59 } |
| 60 |
| 61 void PermissionsBrowserTest::CommonFailsIfDismissed() { |
| 62 EXPECT_EQ(0, prompt_factory()->total_request_count()); |
| 63 prompt_factory()->set_response_type(PermissionRequestManager::DISMISS); |
| 64 TriggerPrompt(); |
| 65 |
| 66 EXPECT_EQ(1, prompt_factory()->total_request_count()); |
| 67 EXPECT_FALSE(FeatureUsageSucceeds()); |
| 68 } |
| 69 |
| 70 void PermissionsBrowserTest::CommonFailsIfBlocked() { |
| 71 EXPECT_EQ(0, prompt_factory()->total_request_count()); |
| 72 prompt_factory()->set_response_type(PermissionRequestManager::DENY_ALL); |
| 73 TriggerPrompt(); |
| 74 |
| 75 EXPECT_EQ(1, prompt_factory()->total_request_count()); |
| 76 EXPECT_FALSE(FeatureUsageSucceeds()); |
| 77 } |
| 78 |
| 79 void PermissionsBrowserTest::CommonSucceedsIfAllowed() { |
| 80 EXPECT_EQ(0, prompt_factory()->total_request_count()); |
| 81 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| 82 TriggerPrompt(); |
| 83 |
| 84 EXPECT_EQ(1, prompt_factory()->total_request_count()); |
| 85 EXPECT_TRUE(FeatureUsageSucceeds()); |
| 86 } |
| OLD | NEW |