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
3 // found in the LICENSE file.
7 #include "base/files/file_path.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h"
12 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/test/base/in_process_browser_test.h"
15 #include "chrome/test/base/ui_test_utils.h"
16 #include "components/content_settings/core/common/content_settings_types.h"
17 #include "content/public/test/test_navigation_observer.h"
18 #include "net/test/spawned_test_server/spawned_test_server.h"
19 #include "testing/gtest/include/gtest/gtest.h"
21 const base::FilePath::CharType kDocRoot
[] =
22 FILE_PATH_LITERAL("chrome/test/data");
24 class ContentSettingBubbleModelMixedScriptTest
: public InProcessBrowserTest
{
26 void SetUpInProcessBrowserTestFixture() override
{
28 new net::SpawnedTestServer(
29 net::SpawnedTestServer::TYPE_HTTPS
,
30 net::SpawnedTestServer::SSLOptions(
31 net::SpawnedTestServer::SSLOptions::CERT_OK
),
32 base::FilePath(kDocRoot
)));
33 ASSERT_TRUE(https_server_
->Start());
36 TabSpecificContentSettings
* GetActiveTabSpecificContentSettings() {
37 return TabSpecificContentSettings::FromWebContents(
38 browser()->tab_strip_model()->GetActiveWebContents());
41 scoped_ptr
<net::SpawnedTestServer
> https_server_
;
44 // Tests that a MIXEDSCRIPT type ContentSettingBubbleModel sends appropriate
45 // IPCs to allow the renderer to load unsafe scripts and refresh the page
47 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleModelMixedScriptTest
, MainFrame
) {
48 GURL
url(https_server_
->GetURL(
49 "files/content_setting_bubble/mixed_script.html"));
51 // Load a page with mixed content and do quick verification by looking at
53 ui_test_utils::NavigateToURL(browser(), url
);
55 EXPECT_TRUE(GetActiveTabSpecificContentSettings()->IsContentBlocked(
56 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT
));
58 // Emulate link clicking on the mixed script bubble.
59 scoped_ptr
<ContentSettingBubbleModel
> model(
60 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
61 browser()->content_setting_bubble_model_delegate(),
62 browser()->tab_strip_model()->GetActiveWebContents(),
64 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT
));
65 model
->OnCustomLinkClicked();
68 content::TestNavigationObserver
observer(
69 browser()->tab_strip_model()->GetActiveWebContents());
72 EXPECT_FALSE(GetActiveTabSpecificContentSettings()->IsContentBlocked(
73 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT
));
76 // Tests that a MIXEDSCRIPT type ContentSettingBubbleModel works for an iframe.
77 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleModelMixedScriptTest
, Iframe
) {
78 GURL
url(https_server_
->GetURL(
79 "files/content_setting_bubble/mixed_script_in_iframe.html"));
81 ui_test_utils::NavigateToURL(browser(), url
);
83 EXPECT_TRUE(GetActiveTabSpecificContentSettings()->IsContentBlocked(
84 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT
));
86 scoped_ptr
<ContentSettingBubbleModel
> model(
87 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
88 browser()->content_setting_bubble_model_delegate(),
89 browser()->tab_strip_model()->GetActiveWebContents(),
91 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT
));
92 model
->OnCustomLinkClicked();
94 content::TestNavigationObserver
observer(
95 browser()->tab_strip_model()->GetActiveWebContents());
98 EXPECT_FALSE(GetActiveTabSpecificContentSettings()->IsContentBlocked(
99 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT
));