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

Side by Side Diff: chrome/browser/content_settings/content_settings_browsertest.cc

Issue 10544056: TabContentsWrapper -> TabContents, part 9. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/path_service.h" 6 #include "base/path_service.h"
7 #include "base/stringprintf.h" 7 #include "base/stringprintf.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/content_settings/cookie_settings.h" 9 #include "chrome/browser/content_settings/cookie_settings.h"
10 #include "chrome/browser/content_settings/host_content_settings_map.h" 10 #include "chrome/browser/content_settings/host_content_settings_map.h"
11 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 11 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 14 #include "chrome/browser/ui/tab_contents/tab_contents.h"
15 #include "chrome/common/render_messages.h" 15 #include "chrome/common/render_messages.h"
16 #include "chrome/test/base/in_process_browser_test.h" 16 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
18 #include "content/public/browser/render_view_host.h" 18 #include "content/public/browser/render_view_host.h"
19 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
20 #include "content/public/common/content_switches.h" 20 #include "content/public/common/content_switches.h"
21 #include "net/test/test_server.h" 21 #include "net/test/test_server.h"
22 22
23 // Regression test for http://crbug.com/63649. 23 // Regression test for http://crbug.com/63649.
24 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, RedirectLoopCookies) { 24 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, RedirectLoopCookies) {
25 ASSERT_TRUE(test_server()->Start()); 25 ASSERT_TRUE(test_server()->Start());
26 26
27 GURL test_url = test_server()->GetURL("files/redirect-loop.html"); 27 GURL test_url = test_server()->GetURL("files/redirect-loop.html");
28 28
29 CookieSettings::Factory::GetForProfile(browser()->profile())-> 29 CookieSettings::Factory::GetForProfile(browser()->profile())->
30 SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); 30 SetDefaultCookieSetting(CONTENT_SETTING_BLOCK);
31 31
32 ui_test_utils::NavigateToURL(browser(), test_url); 32 ui_test_utils::NavigateToURL(browser(), test_url);
33 33
34 TabContentsWrapper* tab_contents = browser()->GetSelectedTabContentsWrapper(); 34 TabContents* tab_contents = browser()->GetActiveTabContents();
35 ASSERT_EQ(UTF8ToUTF16(test_url.spec() + " failed to load"), 35 ASSERT_EQ(UTF8ToUTF16(test_url.spec() + " failed to load"),
36 tab_contents->web_contents()->GetTitle()); 36 tab_contents->web_contents()->GetTitle());
37 37
38 EXPECT_TRUE(tab_contents->content_settings()->IsContentBlocked( 38 EXPECT_TRUE(tab_contents->content_settings()->IsContentBlocked(
39 CONTENT_SETTINGS_TYPE_COOKIES)); 39 CONTENT_SETTINGS_TYPE_COOKIES));
40 } 40 }
41 41
42 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, ContentSettingsBlockDataURLs) { 42 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, ContentSettingsBlockDataURLs) {
43 GURL url("data:text/html,<title>Data URL</title><script>alert(1)</script>"); 43 GURL url("data:text/html,<title>Data URL</title><script>alert(1)</script>");
44 44
45 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( 45 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
46 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); 46 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
47 47
48 ui_test_utils::NavigateToURL(browser(), url); 48 ui_test_utils::NavigateToURL(browser(), url);
49 49
50 TabContentsWrapper* tab_contents = browser()->GetSelectedTabContentsWrapper(); 50 TabContents* tab_contents = browser()->GetActiveTabContents();
51 ASSERT_EQ(UTF8ToUTF16("Data URL"), tab_contents->web_contents()->GetTitle()); 51 ASSERT_EQ(UTF8ToUTF16("Data URL"), tab_contents->web_contents()->GetTitle());
52 52
53 EXPECT_TRUE(tab_contents->content_settings()->IsContentBlocked( 53 EXPECT_TRUE(tab_contents->content_settings()->IsContentBlocked(
54 CONTENT_SETTINGS_TYPE_JAVASCRIPT)); 54 CONTENT_SETTINGS_TYPE_JAVASCRIPT));
55 } 55 }
56 56
57 // Tests that if redirect across origins occurs, the new process still gets the 57 // Tests that if redirect across origins occurs, the new process still gets the
58 // content settings before the resource headers. 58 // content settings before the resource headers.
59 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, RedirectCrossOrigin) { 59 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, RedirectCrossOrigin) {
60 ASSERT_TRUE(test_server()->Start()); 60 ASSERT_TRUE(test_server()->Start());
61 61
62 net::HostPortPair host_port = test_server()->host_port_pair(); 62 net::HostPortPair host_port = test_server()->host_port_pair();
63 DCHECK_EQ(host_port.host(), std::string("127.0.0.1")); 63 DCHECK_EQ(host_port.host(), std::string("127.0.0.1"));
64 64
65 std::string redirect(base::StringPrintf( 65 std::string redirect(base::StringPrintf(
66 "http://localhost:%d/files/redirect-cross-origin.html", 66 "http://localhost:%d/files/redirect-cross-origin.html",
67 host_port.port())); 67 host_port.port()));
68 GURL test_url = test_server()->GetURL("server-redirect?" + redirect); 68 GURL test_url = test_server()->GetURL("server-redirect?" + redirect);
69 69
70 CookieSettings::Factory::GetForProfile(browser()->profile())-> 70 CookieSettings::Factory::GetForProfile(browser()->profile())->
71 SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); 71 SetDefaultCookieSetting(CONTENT_SETTING_BLOCK);
72 72
73 ui_test_utils::NavigateToURL(browser(), test_url); 73 ui_test_utils::NavigateToURL(browser(), test_url);
74 74
75 TabContentsWrapper* tab_contents = browser()->GetSelectedTabContentsWrapper(); 75 TabContents* tab_contents = browser()->GetActiveTabContents();
76 76
77 EXPECT_TRUE(tab_contents->content_settings()->IsContentBlocked( 77 EXPECT_TRUE(tab_contents->content_settings()->IsContentBlocked(
78 CONTENT_SETTINGS_TYPE_COOKIES)); 78 CONTENT_SETTINGS_TYPE_COOKIES));
79 } 79 }
80 80
81 #if !defined(USE_AURA) // No NPAPI plugins with Aura. 81 #if !defined(USE_AURA) // No NPAPI plugins with Aura.
82 82
83 class ClickToPlayPluginTest : public InProcessBrowserTest { 83 class ClickToPlayPluginTest : public InProcessBrowserTest {
84 public: 84 public:
85 ClickToPlayPluginTest() { 85 ClickToPlayPluginTest() {
(...skipping 16 matching lines...) Expand all
102 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( 102 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
103 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); 103 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
104 104
105 GURL url = ui_test_utils::GetTestUrl( 105 GURL url = ui_test_utils::GetTestUrl(
106 FilePath().AppendASCII("npapi"), 106 FilePath().AppendASCII("npapi"),
107 FilePath().AppendASCII("clicktoplay.html")); 107 FilePath().AppendASCII("clicktoplay.html"));
108 ui_test_utils::NavigateToURL(browser(), url); 108 ui_test_utils::NavigateToURL(browser(), url);
109 109
110 string16 expected_title(ASCIIToUTF16("OK")); 110 string16 expected_title(ASCIIToUTF16("OK"));
111 ui_test_utils::TitleWatcher title_watcher( 111 ui_test_utils::TitleWatcher title_watcher(
112 browser()->GetSelectedWebContents(), expected_title); 112 browser()->GetActiveWebContents(), expected_title);
113 113
114 content::RenderViewHost* host = 114 content::RenderViewHost* host =
115 browser()->GetSelectedWebContents()->GetRenderViewHost(); 115 browser()->GetActiveWebContents()->GetRenderViewHost();
116 host->Send(new ChromeViewMsg_LoadBlockedPlugins( 116 host->Send(new ChromeViewMsg_LoadBlockedPlugins(
117 host->GetRoutingID(), std::string())); 117 host->GetRoutingID(), std::string()));
118 118
119 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 119 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
120 } 120 }
121 121
122 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, LoadAllBlockedPlugins) { 122 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, LoadAllBlockedPlugins) {
123 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( 123 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
124 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); 124 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
125 125
126 GURL url = ui_test_utils::GetTestUrl( 126 GURL url = ui_test_utils::GetTestUrl(
127 FilePath().AppendASCII("npapi"), 127 FilePath().AppendASCII("npapi"),
128 FilePath().AppendASCII("load_all_blocked_plugins.html")); 128 FilePath().AppendASCII("load_all_blocked_plugins.html"));
129 ui_test_utils::NavigateToURL(browser(), url); 129 ui_test_utils::NavigateToURL(browser(), url);
130 130
131 string16 expected_title1(ASCIIToUTF16("1")); 131 string16 expected_title1(ASCIIToUTF16("1"));
132 ui_test_utils::TitleWatcher title_watcher1( 132 ui_test_utils::TitleWatcher title_watcher1(
133 browser()->GetSelectedWebContents(), expected_title1); 133 browser()->GetActiveWebContents(), expected_title1);
134 134
135 content::RenderViewHost* host = 135 content::RenderViewHost* host =
136 browser()->GetSelectedWebContents()->GetRenderViewHost(); 136 browser()->GetActiveWebContents()->GetRenderViewHost();
137 host->Send(new ChromeViewMsg_LoadBlockedPlugins( 137 host->Send(new ChromeViewMsg_LoadBlockedPlugins(
138 host->GetRoutingID(), std::string())); 138 host->GetRoutingID(), std::string()));
139 EXPECT_EQ(expected_title1, title_watcher1.WaitAndGetTitle()); 139 EXPECT_EQ(expected_title1, title_watcher1.WaitAndGetTitle());
140 140
141 string16 expected_title2(ASCIIToUTF16("2")); 141 string16 expected_title2(ASCIIToUTF16("2"));
142 ui_test_utils::TitleWatcher title_watcher2( 142 ui_test_utils::TitleWatcher title_watcher2(
143 browser()->GetSelectedWebContents(), expected_title2); 143 browser()->GetActiveWebContents(), expected_title2);
144 144
145 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( 145 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
146 browser()->GetSelectedWebContents()->GetRenderViewHost(), 146 browser()->GetActiveWebContents()->GetRenderViewHost(),
147 L"", L"window.inject()")); 147 L"", L"window.inject()"));
148 148
149 EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle()); 149 EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle());
150 } 150 }
151 151
152 // If this flakes, use http://crbug.com/113057. 152 // If this flakes, use http://crbug.com/113057.
153 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, NoCallbackAtLoad) { 153 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, NoCallbackAtLoad) {
154 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( 154 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
155 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); 155 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
156 156
157 GURL url("data:application/vnd.npapi-test,CallOnStartup();"); 157 GURL url("data:application/vnd.npapi-test,CallOnStartup();");
158 ui_test_utils::NavigateToURL(browser(), url); 158 ui_test_utils::NavigateToURL(browser(), url);
159 159
160 // Inject the callback function into the HTML page generated by the browser. 160 // Inject the callback function into the HTML page generated by the browser.
161 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( 161 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
162 browser()->GetSelectedWebContents()->GetRenderViewHost(), 162 browser()->GetActiveWebContents()->GetRenderViewHost(),
163 L"", L"CallOnStartup = function() { document.title = \"OK\"; }")); 163 L"", L"CallOnStartup = function() { document.title = \"OK\"; }"));
164 164
165 string16 expected_title(ASCIIToUTF16("OK")); 165 string16 expected_title(ASCIIToUTF16("OK"));
166 ui_test_utils::TitleWatcher title_watcher( 166 ui_test_utils::TitleWatcher title_watcher(
167 browser()->GetSelectedWebContents(), expected_title); 167 browser()->GetActiveWebContents(), expected_title);
168 168
169 content::RenderViewHost* host = 169 content::RenderViewHost* host =
170 browser()->GetSelectedWebContents()->GetRenderViewHost(); 170 browser()->GetActiveWebContents()->GetRenderViewHost();
171 host->Send(new ChromeViewMsg_LoadBlockedPlugins( 171 host->Send(new ChromeViewMsg_LoadBlockedPlugins(
172 host->GetRoutingID(), std::string())); 172 host->GetRoutingID(), std::string()));
173 173
174 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 174 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
175 } 175 }
176 176
177 #endif // !defined(USE_AURA) 177 #endif // !defined(USE_AURA)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698