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

Side by Side Diff: chrome/browser/browser_browsertest.cc

Issue 6312154: Remove wstring from RVH's run Javascript command.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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 <string> 5 #include <string>
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/sys_info.h" 9 #include "base/sys_info.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 29 matching lines...) Expand all
40 #include "net/test/test_server.h" 40 #include "net/test/test_server.h"
41 #include "ui/base/l10n/l10n_util.h" 41 #include "ui/base/l10n/l10n_util.h"
42 42
43 #if defined(OS_WIN) 43 #if defined(OS_WIN)
44 #include "base/i18n/rtl.h" 44 #include "base/i18n/rtl.h"
45 #include "chrome/browser/browser_process.h" 45 #include "chrome/browser/browser_process.h"
46 #endif 46 #endif
47 47
48 namespace { 48 namespace {
49 49
50 const std::string BEFORE_UNLOAD_HTML = 50 const char* kBeforeUnloadHTML =
51 "<html><head><title>beforeunload</title></head><body>" 51 "<html><head><title>beforeunload</title></head><body>"
52 "<script>window.onbeforeunload=function(e){return 'foo'}</script>" 52 "<script>window.onbeforeunload=function(e){return 'foo'}</script>"
53 "</body></html>"; 53 "</body></html>";
54 54
55 const std::wstring OPEN_NEW_BEFOREUNLOAD_PAGE = 55 const char* kOpenNewBeforeUnloadPage =
56 L"w=window.open(); w.onbeforeunload=function(e){return 'foo'};"; 56 "w=window.open(); w.onbeforeunload=function(e){return 'foo'};";
57 57
58 const FilePath::CharType* kTitle1File = FILE_PATH_LITERAL("title1.html"); 58 const FilePath::CharType* kTitle1File = FILE_PATH_LITERAL("title1.html");
59 const FilePath::CharType* kTitle2File = FILE_PATH_LITERAL("title2.html"); 59 const FilePath::CharType* kTitle2File = FILE_PATH_LITERAL("title2.html");
60 60
61 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); 61 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data");
62 62
63 // Given a page title, returns the expected window caption string. 63 // Given a page title, returns the expected window caption string.
64 std::wstring WindowCaptionFromPageTitle(std::wstring page_title) { 64 std::wstring WindowCaptionFromPageTitle(std::wstring page_title) {
65 #if defined(OS_MACOSX) || defined(OS_CHROMEOS) 65 #if defined(OS_MACOSX) || defined(OS_CHROMEOS)
66 // On Mac or ChromeOS, we don't want to suffix the page title with 66 // On Mac or ChromeOS, we don't want to suffix the page title with
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 204
205 IN_PROC_BROWSER_TEST_F(BrowserTest, JavascriptAlertActivatesTab) { 205 IN_PROC_BROWSER_TEST_F(BrowserTest, JavascriptAlertActivatesTab) {
206 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), 206 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
207 FilePath(kTitle1File))); 207 FilePath(kTitle1File)));
208 ui_test_utils::NavigateToURL(browser(), url); 208 ui_test_utils::NavigateToURL(browser(), url);
209 AddTabAtIndex(0, url, PageTransition::TYPED); 209 AddTabAtIndex(0, url, PageTransition::TYPED);
210 EXPECT_EQ(2, browser()->tab_count()); 210 EXPECT_EQ(2, browser()->tab_count());
211 EXPECT_EQ(0, browser()->selected_index()); 211 EXPECT_EQ(0, browser()->selected_index());
212 TabContents* second_tab = browser()->GetTabContentsAt(1); 212 TabContents* second_tab = browser()->GetTabContentsAt(1);
213 ASSERT_TRUE(second_tab); 213 ASSERT_TRUE(second_tab);
214 second_tab->render_view_host()->ExecuteJavascriptInWebFrame(L"", 214 second_tab->render_view_host()->ExecuteJavascriptInWebFrame(
215 L"alert('Activate!');"); 215 string16(),
216 ASCIIToUTF16("alert('Activate!');"));
216 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); 217 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
217 alert->CloseModalDialog(); 218 alert->CloseModalDialog();
218 EXPECT_EQ(2, browser()->tab_count()); 219 EXPECT_EQ(2, browser()->tab_count());
219 EXPECT_EQ(1, browser()->selected_index()); 220 EXPECT_EQ(1, browser()->selected_index());
220 } 221 }
221 222
222 // Create 34 tabs and verify that a lot of processes have been created. The 223 // Create 34 tabs and verify that a lot of processes have been created. The
223 // exact number of processes depends on the amount of memory. Previously we 224 // exact number of processes depends on the amount of memory. Previously we
224 // had a hard limit of 31 processes and this test is mainly directed at 225 // had a hard limit of 31 processes and this test is mainly directed at
225 // verifying that we don't crash when we pass this limit. 226 // verifying that we don't crash when we pass this limit.
(...skipping 13 matching lines...) Expand all
239 if (base::SysInfo::AmountOfPhysicalMemoryMB() >= 2048) { 240 if (base::SysInfo::AmountOfPhysicalMemoryMB() >= 2048) {
240 EXPECT_GE(CountRenderProcessHosts(), 24); 241 EXPECT_GE(CountRenderProcessHosts(), 24);
241 } else { 242 } else {
242 EXPECT_LE(CountRenderProcessHosts(), 23); 243 EXPECT_LE(CountRenderProcessHosts(), 23);
243 } 244 }
244 } 245 }
245 246
246 // Test for crbug.com/22004. Reloading a page with a before unload handler and 247 // Test for crbug.com/22004. Reloading a page with a before unload handler and
247 // then canceling the dialog should not leave the throbber spinning. 248 // then canceling the dialog should not leave the throbber spinning.
248 IN_PROC_BROWSER_TEST_F(BrowserTest, ReloadThenCancelBeforeUnload) { 249 IN_PROC_BROWSER_TEST_F(BrowserTest, ReloadThenCancelBeforeUnload) {
249 GURL url("data:text/html," + BEFORE_UNLOAD_HTML); 250 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML);
250 ui_test_utils::NavigateToURL(browser(), url); 251 ui_test_utils::NavigateToURL(browser(), url);
251 252
252 // Navigate to another page, but click cancel in the dialog. Make sure that 253 // Navigate to another page, but click cancel in the dialog. Make sure that
253 // the throbber stops spinning. 254 // the throbber stops spinning.
254 browser()->Reload(CURRENT_TAB); 255 browser()->Reload(CURRENT_TAB);
255 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); 256 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
256 alert->CloseModalDialog(); 257 alert->CloseModalDialog();
257 EXPECT_FALSE(browser()->GetSelectedTabContents()->is_loading()); 258 EXPECT_FALSE(browser()->GetSelectedTabContents()->is_loading());
258 259
259 // Clear the beforeunload handler so the test can easily exit. 260 // Clear the beforeunload handler so the test can easily exit.
260 browser()->GetSelectedTabContents()->render_view_host()-> 261 browser()->GetSelectedTabContents()->render_view_host()->
261 ExecuteJavascriptInWebFrame(L"", L"onbeforeunload=null;"); 262 ExecuteJavascriptInWebFrame(string16(),
263 ASCIIToUTF16("onbeforeunload=null;"));
262 } 264 }
263 265
264 // Crashy on mac. http://crbug.com/38522 266 // Crashy on mac. http://crbug.com/38522
265 #if defined(OS_MACOSX) 267 #if defined(OS_MACOSX)
266 #define MAYBE_SingleBeforeUnloadAfterWindowClose \ 268 #define MAYBE_SingleBeforeUnloadAfterWindowClose \
267 DISABLED_SingleBeforeUnloadAfterWindowClose 269 DISABLED_SingleBeforeUnloadAfterWindowClose
268 #else 270 #else
269 #define MAYBE_SingleBeforeUnloadAfterWindowClose \ 271 #define MAYBE_SingleBeforeUnloadAfterWindowClose \
270 SingleBeforeUnloadAfterWindowClose 272 SingleBeforeUnloadAfterWindowClose
271 #endif 273 #endif
272 274
273 // Test for crbug.com/11647. A page closed with window.close() should not have 275 // Test for crbug.com/11647. A page closed with window.close() should not have
274 // two beforeunload dialogs shown. 276 // two beforeunload dialogs shown.
275 IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_SingleBeforeUnloadAfterWindowClose) { 277 IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_SingleBeforeUnloadAfterWindowClose) {
276 browser()->GetSelectedTabContents()->render_view_host()-> 278 browser()->GetSelectedTabContents()->render_view_host()->
277 ExecuteJavascriptInWebFrame(L"", OPEN_NEW_BEFOREUNLOAD_PAGE); 279 ExecuteJavascriptInWebFrame(string16(),
280 ASCIIToUTF16(kOpenNewBeforeUnloadPage));
278 281
279 // Close the new window with JavaScript, which should show a single 282 // Close the new window with JavaScript, which should show a single
280 // beforeunload dialog. Then show another alert, to make it easy to verify 283 // beforeunload dialog. Then show another alert, to make it easy to verify
281 // that a second beforeunload dialog isn't shown. 284 // that a second beforeunload dialog isn't shown.
282 browser()->GetTabContentsAt(0)->render_view_host()-> 285 browser()->GetTabContentsAt(0)->render_view_host()->
283 ExecuteJavascriptInWebFrame(L"", L"w.close(); alert('bar');"); 286 ExecuteJavascriptInWebFrame(string16(),
287 ASCIIToUTF16("w.close(); alert('bar');"));
284 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); 288 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
285 alert->native_dialog()->AcceptAppModalDialog(); 289 alert->native_dialog()->AcceptAppModalDialog();
286 290
287 alert = ui_test_utils::WaitForAppModalDialog(); 291 alert = ui_test_utils::WaitForAppModalDialog();
288 EXPECT_FALSE(static_cast<JavaScriptAppModalDialog*>(alert)-> 292 EXPECT_FALSE(static_cast<JavaScriptAppModalDialog*>(alert)->
289 is_before_unload_dialog()); 293 is_before_unload_dialog());
290 alert->native_dialog()->AcceptAppModalDialog(); 294 alert->native_dialog()->AcceptAppModalDialog();
291 } 295 }
292 296
293 // Test that get_process_idle_time() returns reasonable values when compared 297 // Test that get_process_idle_time() returns reasonable values when compared
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 781
778 // The normal browser should now have four. 782 // The normal browser should now have four.
779 EXPECT_EQ(4, browser()->tab_count()); 783 EXPECT_EQ(4, browser()->tab_count());
780 784
781 // Close the additional browsers. 785 // Close the additional browsers.
782 popup_browser->CloseAllTabs(); 786 popup_browser->CloseAllTabs();
783 app_browser->CloseAllTabs(); 787 app_browser->CloseAllTabs();
784 app_popup_browser->CloseAllTabs(); 788 app_popup_browser->CloseAllTabs();
785 } 789 }
786 #endif 790 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698