OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 9 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" | 11 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" |
12 #include "chrome/browser/ui/browser_finder.h" | 12 #include "chrome/browser/ui/browser_finder.h" |
13 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 13 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
16 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
17 #include "components/content_settings/core/common/content_settings_types.h" | 17 #include "components/content_settings/core/common/content_settings_types.h" |
18 #include "content/public/test/test_navigation_observer.h" | 18 #include "content/public/test/test_navigation_observer.h" |
19 #include "net/test/spawned_test_server/spawned_test_server.h" | 19 #include "net/test/embedded_test_server/embedded_test_server.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 | 21 |
22 const base::FilePath::CharType kDocRoot[] = | 22 const base::FilePath::CharType kDocRoot[] = |
23 FILE_PATH_LITERAL("chrome/test/data"); | 23 FILE_PATH_LITERAL("chrome/test/data"); |
24 | 24 |
25 class ContentSettingBubbleModelMixedScriptTest : public InProcessBrowserTest { | 25 class ContentSettingBubbleModelMixedScriptTest : public InProcessBrowserTest { |
26 protected: | 26 protected: |
27 void SetUpInProcessBrowserTestFixture() override { | 27 void SetUpInProcessBrowserTestFixture() override { |
28 https_server_.reset( | 28 https_server_.reset( |
29 new net::SpawnedTestServer( | 29 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); |
30 net::SpawnedTestServer::TYPE_HTTPS, | 30 https_server_->ServeFilesFromSourceDirectory(base::FilePath(kDocRoot)); |
31 net::SpawnedTestServer::SSLOptions( | |
32 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
33 base::FilePath(kDocRoot))); | |
34 ASSERT_TRUE(https_server_->Start()); | 31 ASSERT_TRUE(https_server_->Start()); |
35 } | 32 } |
36 | 33 |
37 TabSpecificContentSettings* GetActiveTabSpecificContentSettings() { | 34 TabSpecificContentSettings* GetActiveTabSpecificContentSettings() { |
38 return TabSpecificContentSettings::FromWebContents( | 35 return TabSpecificContentSettings::FromWebContents( |
39 browser()->tab_strip_model()->GetActiveWebContents()); | 36 browser()->tab_strip_model()->GetActiveWebContents()); |
40 } | 37 } |
41 | 38 |
42 scoped_ptr<net::SpawnedTestServer> https_server_; | 39 scoped_ptr<net::EmbeddedTestServer> https_server_; |
43 }; | 40 }; |
44 | 41 |
45 // Tests that a MIXEDSCRIPT type ContentSettingBubbleModel sends appropriate | 42 // Tests that a MIXEDSCRIPT type ContentSettingBubbleModel sends appropriate |
46 // IPCs to allow the renderer to load unsafe scripts and refresh the page | 43 // IPCs to allow the renderer to load unsafe scripts and refresh the page |
47 // automatically. | 44 // automatically. |
48 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleModelMixedScriptTest, MainFrame) { | 45 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleModelMixedScriptTest, MainFrame) { |
49 GURL url(https_server_->GetURL( | 46 GURL url(https_server_->GetURL("/content_setting_bubble/mixed_script.html")); |
50 "files/content_setting_bubble/mixed_script.html")); | |
51 | 47 |
52 // Load a page with mixed content and do quick verification by looking at | 48 // Load a page with mixed content and do quick verification by looking at |
53 // the title string. | 49 // the title string. |
54 ui_test_utils::NavigateToURL(browser(), url); | 50 ui_test_utils::NavigateToURL(browser(), url); |
55 | 51 |
56 EXPECT_TRUE(GetActiveTabSpecificContentSettings()->IsContentBlocked( | 52 EXPECT_TRUE(GetActiveTabSpecificContentSettings()->IsContentBlocked( |
57 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT)); | 53 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT)); |
58 | 54 |
59 // Emulate link clicking on the mixed script bubble. | 55 // Emulate link clicking on the mixed script bubble. |
60 scoped_ptr<ContentSettingBubbleModel> model( | 56 scoped_ptr<ContentSettingBubbleModel> model( |
(...skipping 11 matching lines...) Expand all Loading... |
72 | 68 |
73 EXPECT_FALSE(GetActiveTabSpecificContentSettings()->IsContentBlocked( | 69 EXPECT_FALSE(GetActiveTabSpecificContentSettings()->IsContentBlocked( |
74 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT)); | 70 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT)); |
75 } | 71 } |
76 | 72 |
77 // Tests that a MIXEDSCRIPT type ContentSettingBubbleModel does not work | 73 // Tests that a MIXEDSCRIPT type ContentSettingBubbleModel does not work |
78 // for an iframe (mixed script in iframes is never allowed and the mixed | 74 // for an iframe (mixed script in iframes is never allowed and the mixed |
79 // content shield isn't shown for it). | 75 // content shield isn't shown for it). |
80 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleModelMixedScriptTest, Iframe) { | 76 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleModelMixedScriptTest, Iframe) { |
81 GURL url(https_server_->GetURL( | 77 GURL url(https_server_->GetURL( |
82 "files/content_setting_bubble/mixed_script_in_iframe.html")); | 78 "/content_setting_bubble/mixed_script_in_iframe.html")); |
83 | 79 |
84 ui_test_utils::NavigateToURL(browser(), url); | 80 ui_test_utils::NavigateToURL(browser(), url); |
85 | 81 |
86 // Blink does not ask the browser to handle mixed content in the case | 82 // Blink does not ask the browser to handle mixed content in the case |
87 // of active subresources in an iframe, so the content type should not | 83 // of active subresources in an iframe, so the content type should not |
88 // be marked as blocked. | 84 // be marked as blocked. |
89 EXPECT_FALSE(GetActiveTabSpecificContentSettings()->IsContentBlocked( | 85 EXPECT_FALSE(GetActiveTabSpecificContentSettings()->IsContentBlocked( |
90 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT)); | 86 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT)); |
91 } | 87 } |
92 | 88 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 EXPECT_EQ(GURL("chrome://settings/contentExceptions#media-stream-camera"), | 141 EXPECT_EQ(GURL("chrome://settings/contentExceptions#media-stream-camera"), |
146 GetActiveTab()->GetLastCommittedURL()); | 142 GetActiveTab()->GetLastCommittedURL()); |
147 | 143 |
148 // The bubble for both media devices links to the the first section of the | 144 // The bubble for both media devices links to the the first section of the |
149 // default media content settings, which is the microphone section. | 145 // default media content settings, which is the microphone section. |
150 ManageMediaStreamSettings(TabSpecificContentSettings::MICROPHONE_ACCESSED | | 146 ManageMediaStreamSettings(TabSpecificContentSettings::MICROPHONE_ACCESSED | |
151 TabSpecificContentSettings::CAMERA_ACCESSED); | 147 TabSpecificContentSettings::CAMERA_ACCESSED); |
152 EXPECT_EQ(GURL("chrome://settings/content#media-stream-mic"), | 148 EXPECT_EQ(GURL("chrome://settings/content#media-stream-mic"), |
153 GetActiveTab()->GetLastCommittedURL()); | 149 GetActiveTab()->GetLastCommittedURL()); |
154 } | 150 } |
OLD | NEW |