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

Side by Side Diff: chrome/browser/ui/tests/browser_uitest.cc

Issue 7740028: Use the request's URL rather than the document's when deciding to swap. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove WaitFor calls. Created 9 years, 4 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/base_paths.h" 5 #include "base/base_paths.h"
6 #include "base/file_path.h" 6 #include "base/file_path.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/sys_info.h" 10 #include "base/sys_info.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 ASSERT_TRUE(session_end_completed); 67 ASSERT_TRUE(session_end_completed);
68 68
69 // Make sure session restore says we didn't crash. 69 // Make sure session restore says we didn't crash.
70 scoped_ptr<DictionaryValue> profile_prefs(GetDefaultProfilePreferences()); 70 scoped_ptr<DictionaryValue> profile_prefs(GetDefaultProfilePreferences());
71 ASSERT_TRUE(profile_prefs.get()); 71 ASSERT_TRUE(profile_prefs.get());
72 ASSERT_TRUE(profile_prefs->GetBoolean(prefs::kSessionExitedCleanly, 72 ASSERT_TRUE(profile_prefs->GetBoolean(prefs::kSessionExitedCleanly,
73 &exited_cleanly)); 73 &exited_cleanly));
74 ASSERT_TRUE(exited_cleanly); 74 ASSERT_TRUE(exited_cleanly);
75 } 75 }
76 76
77 // Test that scripts can fork a new renderer process for a tab in a particular
78 // case (which matches following a link in Gmail). The script must open a new
79 // tab, set its window.opener to null, and redirect it to a cross-site URL.
80 // (Bug 1115708)
81 // This test can only run if V8 is in use, and not KJS, because KJS will not
82 // set window.opener to null properly.
83 #ifdef CHROME_V8
84 TEST_F(BrowserTest, NullOpenerRedirectForksProcess) {
85 net::TestServer test_server(net::TestServer::TYPE_HTTP,
86 FilePath(FILE_PATH_LITERAL("chrome/test/data")));
87 ASSERT_TRUE(test_server.Start());
88
89 FilePath test_file(test_data_directory_);
90 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0));
91 ASSERT_TRUE(window.get());
92 scoped_refptr<TabProxy> tab(window->GetActiveTab());
93 ASSERT_TRUE(tab.get());
94
95 // Start with a file:// url
96 test_file = test_file.AppendASCII("title2.html");
97 tab->NavigateToURL(net::FilePathToFileURL(test_file));
98 int orig_tab_count = -1;
99 ASSERT_TRUE(window->GetTabCount(&orig_tab_count));
100 int orig_process_count = 0;
101 ASSERT_TRUE(GetBrowserProcessCount(&orig_process_count));
102 ASSERT_GE(orig_process_count, 1);
103
104 // Use JavaScript URL to "fork" a new tab, just like Gmail. (Open tab to a
105 // blank page, set its opener to null, and redirect it cross-site.)
106 std::wstring url_prefix(L"javascript:(function(){w=window.open();");
107 GURL fork_url(url_prefix +
108 L"w.opener=null;w.document.location=\"http://localhost:1337\";})()");
109
110 // Make sure that a new tab has been created and that we have a new renderer
111 // process for it.
112 ASSERT_TRUE(tab->NavigateToURLAsync(fork_url));
113 PlatformThread::Sleep(TestTimeouts::action_timeout_ms());
114 int process_count = 0;
115 ASSERT_TRUE(GetBrowserProcessCount(&process_count));
116 ASSERT_EQ(orig_process_count + 1, process_count);
117 int new_tab_count = -1;
118 ASSERT_TRUE(window->GetTabCount(&new_tab_count));
119 ASSERT_EQ(orig_tab_count + 1, new_tab_count);
120 }
121 #endif // CHROME_V8
122
123 // This test fails on ChromeOS (it has never been known to work on it).
124 // Currently flaky on Windows - it has crashed a couple of times.
125 // http://crbug.com/32799
126 #if defined(OS_CHROMEOS)
127 #define MAYBE_OtherRedirectsDontForkProcess DISABLED_OtherRedirectsDontForkProce ss
128 #else
129 #define MAYBE_OtherRedirectsDontForkProcess FLAKY_OtherRedirectsDontForkProcess
130 #endif
131
132 // Tests that non-Gmail-like script redirects (i.e., non-null window.opener) or
133 // a same-page-redirect) will not fork a new process.
134 TEST_F(BrowserTest, MAYBE_OtherRedirectsDontForkProcess) {
135 net::TestServer test_server(net::TestServer::TYPE_HTTP,
136 FilePath(FILE_PATH_LITERAL("chrome/test/data")));
137 ASSERT_TRUE(test_server.Start());
138
139 FilePath test_file(test_data_directory_);
140 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0));
141 ASSERT_TRUE(window.get());
142 scoped_refptr<TabProxy> tab(window->GetActiveTab());
143 ASSERT_TRUE(tab.get());
144
145 // Start with a file:// url
146 test_file = test_file.AppendASCII("title2.html");
147 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS,
148 tab->NavigateToURL(net::FilePathToFileURL(test_file)));
149 int orig_tab_count = -1;
150 ASSERT_TRUE(window->GetTabCount(&orig_tab_count));
151 int orig_process_count = 0;
152 ASSERT_TRUE(GetBrowserProcessCount(&orig_process_count));
153 ASSERT_GE(orig_process_count, 1);
154
155 // Use JavaScript URL to almost fork a new tab, but not quite. (Leave the
156 // opener non-null.) Should not fork a process.
157 std::string url_str = "javascript:(function(){w=window.open(); ";
158 url_str += "w.document.location=\"";
159 url_str += test_server.GetURL("").spec();
160 url_str += "\";})()";
161 GURL dont_fork_url(url_str);
162
163 // Make sure that a new tab but not new process has been created.
164 ASSERT_TRUE(tab->NavigateToURLAsync(dont_fork_url));
165 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms());
166 int process_count = 0;
167 ASSERT_TRUE(GetBrowserProcessCount(&process_count));
168 ASSERT_EQ(orig_process_count, process_count);
169 int new_tab_count = -1;
170 ASSERT_TRUE(window->GetTabCount(&new_tab_count));
171 ASSERT_EQ(orig_tab_count + 1, new_tab_count);
172
173 // Same thing if the current tab tries to redirect itself.
174 url_str = "javascript:(function(){w=window.open(); ";
175 url_str += "document.location=\"";
176 url_str += test_server.GetURL("").spec();
177 url_str += "\";})()";
178 GURL dont_fork_url2(url_str);
179
180 // Make sure that no new process has been created.
181 ASSERT_TRUE(tab->NavigateToURLAsync(dont_fork_url2));
182 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms());
183 ASSERT_TRUE(GetBrowserProcessCount(&process_count));
184 ASSERT_EQ(orig_process_count, process_count);
185 }
186
187 // WindowOpenClose is flaky on ChromeOS and fails consistently on linux views. 77 // WindowOpenClose is flaky on ChromeOS and fails consistently on linux views.
188 // See http://crbug.com/85763. 78 // See http://crbug.com/85763.
189 #if defined (OS_CHROMEOS) 79 #if defined (OS_CHROMEOS)
190 #define MAYBE_WindowOpenClose FLAKY_WindowOpenClose 80 #define MAYBE_WindowOpenClose FLAKY_WindowOpenClose
191 #elif defined(OS_LINUX) && defined(TOOLKIT_VIEWS) 81 #elif defined(OS_LINUX) && defined(TOOLKIT_VIEWS)
192 #define MAYBE_WindowOpenClose FAILS_WindowOpenClose 82 #define MAYBE_WindowOpenClose FAILS_WindowOpenClose
193 #else 83 #else
194 #define MAYBE_WindowOpenClose WindowOpenClose 84 #define MAYBE_WindowOpenClose WindowOpenClose
195 #endif 85 #endif
196 86
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 265
376 // Verify that the window is present. 266 // Verify that the window is present.
377 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); 267 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
378 ASSERT_TRUE(browser.get()); 268 ASSERT_TRUE(browser.get());
379 269
380 // Verify the browser is in application mode. 270 // Verify the browser is in application mode.
381 bool is_application; 271 bool is_application;
382 ASSERT_TRUE(browser->IsApplication(&is_application)); 272 ASSERT_TRUE(browser->IsApplication(&is_application));
383 EXPECT_TRUE(is_application); 273 EXPECT_TRUE(is_application);
384 } 274 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698