| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "app/app_switches.h" | 7 #include "app/app_switches.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "app/message_box_flags.h" | 9 #include "app/message_box_flags.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 ASSERT_TRUE(tab->GetTabTitle(&title)); | 226 ASSERT_TRUE(tab->GetTabTitle(&title)); |
| 227 ASSERT_STREQ(L"Title Of Awesomeness", title.c_str()); | 227 ASSERT_STREQ(L"Title Of Awesomeness", title.c_str()); |
| 228 } | 228 } |
| 229 | 229 |
| 230 TEST_F(AutomationProxyTest, ActivateTab) { | 230 TEST_F(AutomationProxyTest, ActivateTab) { |
| 231 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 231 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
| 232 ASSERT_TRUE(window.get()); | 232 ASSERT_TRUE(window.get()); |
| 233 | 233 |
| 234 ASSERT_TRUE(window->AppendTab(GURL("about:blank"))); | 234 ASSERT_TRUE(window->AppendTab(GURL("about:blank"))); |
| 235 | 235 |
| 236 int at_index = 1; | 236 ASSERT_TRUE(window->ActivateTab(1)); |
| 237 ASSERT_TRUE(window->ActivateTab(at_index)); | |
| 238 int active_tab_index = -1; | 237 int active_tab_index = -1; |
| 239 ASSERT_TRUE(window->GetActiveTabIndex(&active_tab_index)); | 238 ASSERT_TRUE(window->GetActiveTabIndex(&active_tab_index)); |
| 240 ASSERT_EQ(at_index, active_tab_index); | 239 ASSERT_EQ(1, active_tab_index); |
| 241 | 240 |
| 242 at_index = 0; | 241 ASSERT_TRUE(window->ActivateTab(0)); |
| 243 ASSERT_TRUE(window->ActivateTab(at_index)); | |
| 244 ASSERT_TRUE(window->GetActiveTabIndex(&active_tab_index)); | 242 ASSERT_TRUE(window->GetActiveTabIndex(&active_tab_index)); |
| 245 ASSERT_EQ(at_index, active_tab_index); | 243 ASSERT_EQ(0, active_tab_index); |
| 246 } | 244 } |
| 247 | 245 |
| 248 | |
| 249 TEST_F(AutomationProxyTest, GetTab) { | 246 TEST_F(AutomationProxyTest, GetTab) { |
| 250 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 247 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
| 251 ASSERT_TRUE(window.get()); | 248 ASSERT_TRUE(window.get()); |
| 252 { | 249 { |
| 253 scoped_refptr<TabProxy> tab(window->GetTab(0)); | 250 scoped_refptr<TabProxy> tab(window->GetTab(0)); |
| 254 ASSERT_TRUE(tab.get()); | 251 ASSERT_TRUE(tab.get()); |
| 255 std::wstring title; | 252 std::wstring title; |
| 256 ASSERT_TRUE(tab->GetTabTitle(&title)); | 253 ASSERT_TRUE(tab->GetTabTitle(&title)); |
| 257 // BUG [634097] : expected title should be "about:blank" | 254 // BUG [634097] : expected title should be "about:blank" |
| 258 ASSERT_STREQ(L"", title.c_str()); | 255 ASSERT_STREQ(L"", title.c_str()); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 FilePath document1_; | 354 FilePath document1_; |
| 358 FilePath document2_; | 355 FilePath document2_; |
| 359 }; | 356 }; |
| 360 | 357 |
| 361 TEST_F(AutomationProxyTest2, GetActiveTabIndex) { | 358 TEST_F(AutomationProxyTest2, GetActiveTabIndex) { |
| 362 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 359 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
| 363 ASSERT_TRUE(window.get()); | 360 ASSERT_TRUE(window.get()); |
| 364 | 361 |
| 365 int active_tab_index = -1; | 362 int active_tab_index = -1; |
| 366 ASSERT_TRUE(window->GetActiveTabIndex(&active_tab_index)); | 363 ASSERT_TRUE(window->GetActiveTabIndex(&active_tab_index)); |
| 367 int tab_count; | |
| 368 ASSERT_TRUE(window->GetTabCount(&tab_count)); | |
| 369 ASSERT_EQ(0, active_tab_index); | 364 ASSERT_EQ(0, active_tab_index); |
| 370 int at_index = 1; | 365 |
| 371 ASSERT_TRUE(window->ActivateTab(at_index)); | 366 ASSERT_TRUE(window->ActivateTab(1)); |
| 372 ASSERT_TRUE(window->GetActiveTabIndex(&active_tab_index)); | 367 ASSERT_TRUE(window->GetActiveTabIndex(&active_tab_index)); |
| 373 ASSERT_EQ(at_index, active_tab_index); | 368 ASSERT_EQ(1, active_tab_index); |
| 374 } | 369 } |
| 375 | 370 |
| 376 TEST_F(AutomationProxyTest2, GetTabTitle) { | 371 TEST_F(AutomationProxyTest2, GetTabTitle) { |
| 377 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 372 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
| 378 ASSERT_TRUE(window.get()); | 373 ASSERT_TRUE(window.get()); |
| 379 scoped_refptr<TabProxy> tab(window->GetTab(0)); | 374 scoped_refptr<TabProxy> tab(window->GetTab(0)); |
| 380 ASSERT_TRUE(tab.get()); | 375 ASSERT_TRUE(tab.get()); |
| 381 std::wstring title; | 376 std::wstring title; |
| 382 ASSERT_TRUE(tab->GetTabTitle(&title)); | 377 ASSERT_TRUE(tab->GetTabTitle(&title)); |
| 383 ASSERT_STREQ(L"title1.html", title.c_str()); | 378 ASSERT_STREQ(L"title1.html", title.c_str()); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 ASSERT_TRUE(tab->NavigateToURLAsync(newurl)); | 430 ASSERT_TRUE(tab->NavigateToURLAsync(newurl)); |
| 436 std::string value = WaitUntilCookieNonEmpty(tab.get(), newurl, "foo", | 431 std::string value = WaitUntilCookieNonEmpty(tab.get(), newurl, "foo", |
| 437 action_max_timeout_ms()); | 432 action_max_timeout_ms()); |
| 438 ASSERT_STREQ("baz", value.c_str()); | 433 ASSERT_STREQ("baz", value.c_str()); |
| 439 } | 434 } |
| 440 | 435 |
| 441 TEST_F(AutomationProxyTest, AcceleratorNewTab) { | 436 TEST_F(AutomationProxyTest, AcceleratorNewTab) { |
| 442 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 437 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
| 443 | 438 |
| 444 int tab_count = -1; | 439 int tab_count = -1; |
| 445 ASSERT_TRUE(window->GetTabCount(&tab_count)); | |
| 446 EXPECT_EQ(1, tab_count); | |
| 447 | |
| 448 ASSERT_TRUE(window->RunCommand(IDC_NEW_TAB)); | 440 ASSERT_TRUE(window->RunCommand(IDC_NEW_TAB)); |
| 449 ASSERT_TRUE(window->GetTabCount(&tab_count)); | 441 ASSERT_TRUE(window->GetTabCount(&tab_count)); |
| 450 EXPECT_EQ(2, tab_count); | 442 EXPECT_EQ(2, tab_count); |
| 451 scoped_refptr<TabProxy> tab(window->GetTab(tab_count - 1)); | 443 |
| 444 scoped_refptr<TabProxy> tab(window->GetTab(1)); |
| 452 ASSERT_TRUE(tab.get()); | 445 ASSERT_TRUE(tab.get()); |
| 453 } | 446 } |
| 454 | 447 |
| 455 class AutomationProxyTest4 : public UITest { | 448 class AutomationProxyTest4 : public UITest { |
| 456 protected: | 449 protected: |
| 457 AutomationProxyTest4() : UITest() { | 450 AutomationProxyTest4() : UITest() { |
| 458 dom_automation_enabled_ = true; | 451 dom_automation_enabled_ = true; |
| 459 } | 452 } |
| 460 }; | 453 }; |
| 461 | 454 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 | 552 |
| 560 std::wstring xpath2 = L"/html/body/iframe"; | 553 std::wstring xpath2 = L"/html/body/iframe"; |
| 561 std::wstring jscript2 = CreateJSStringForDOMQuery(L"myspan"); | 554 std::wstring jscript2 = CreateJSStringForDOMQuery(L"myspan"); |
| 562 ASSERT_TRUE(tab->ExecuteAndExtractString(xpath2, jscript2, &actual)); | 555 ASSERT_TRUE(tab->ExecuteAndExtractString(xpath2, jscript2, &actual)); |
| 563 ASSERT_EQ(L"SPAN", actual); | 556 ASSERT_EQ(L"SPAN", actual); |
| 564 | 557 |
| 565 std::wstring xpath3 = L"/html/body/iframe\n/html/body/iframe"; | 558 std::wstring xpath3 = L"/html/body/iframe\n/html/body/iframe"; |
| 566 std::wstring jscript3 = CreateJSStringForDOMQuery(L"mydiv"); | 559 std::wstring jscript3 = CreateJSStringForDOMQuery(L"mydiv"); |
| 567 ASSERT_TRUE(tab->ExecuteAndExtractString(xpath3, jscript3, &actual)); | 560 ASSERT_TRUE(tab->ExecuteAndExtractString(xpath3, jscript3, &actual)); |
| 568 ASSERT_EQ(L"DIV", actual); | 561 ASSERT_EQ(L"DIV", actual); |
| 569 | |
| 570 // TODO(evanm): fix or remove this. | |
| 571 // This part of the test appears to verify that executing JS fails | |
| 572 // non-HTML pages, but the new tab is now HTML so this test isn't | |
| 573 // correct. | |
| 574 #if 0 | |
| 575 // Open a new Destinations tab to execute script inside. | |
| 576 window->RunCommand(IDC_NEWTAB); | |
| 577 tab = window->GetTab(1); | |
| 578 ASSERT_TRUE(tab.get()); | |
| 579 ASSERT_TRUE(window->ActivateTab(1)); | |
| 580 | |
| 581 ASSERT_FALSE(tab->ExecuteAndExtractString(xpath1, jscript1, &actual)); | |
| 582 #endif | |
| 583 } | 562 } |
| 584 | 563 |
| 585 // TODO(port): Need to port constrained_window_proxy.* first. | |
| 586 #if defined(OS_WIN) | |
| 587 TEST_F(AutomationProxyTest, BlockedPopupTest) { | 564 TEST_F(AutomationProxyTest, BlockedPopupTest) { |
| 588 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 565 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
| 589 ASSERT_TRUE(window.get()); | 566 ASSERT_TRUE(window.get()); |
| 590 | 567 |
| 591 scoped_refptr<TabProxy> tab(window->GetTab(0)); | 568 scoped_refptr<TabProxy> tab(window->GetTab(0)); |
| 592 ASSERT_TRUE(tab.get()); | 569 ASSERT_TRUE(tab.get()); |
| 593 | 570 |
| 594 FilePath filename(test_data_directory_); | 571 FilePath filename(test_data_directory_); |
| 595 filename = filename.AppendASCII("constrained_files"); | 572 filename = filename.AppendASCII("constrained_files"); |
| 596 filename = filename.AppendASCII("constrained_window.html"); | 573 filename = filename.AppendASCII("constrained_window.html"); |
| 597 | 574 |
| 598 ASSERT_TRUE(tab->NavigateToURL(net::FilePathToFileURL(filename))); | 575 ASSERT_TRUE(tab->NavigateToURL(net::FilePathToFileURL(filename))); |
| 599 | 576 |
| 600 ASSERT_TRUE(tab->WaitForBlockedPopupCountToChangeTo(2, 5000)); | 577 ASSERT_TRUE(tab->WaitForBlockedPopupCountToChangeTo(2, |
| 578 action_max_timeout_ms())); |
| 601 } | 579 } |
| 602 | 580 |
| 603 #endif // defined(OS_WIN) | |
| 604 | |
| 605 // TODO(port): Remove HWND if possible | 581 // TODO(port): Remove HWND if possible |
| 606 #if defined(OS_WIN) | 582 #if defined(OS_WIN) |
| 607 | 583 |
| 608 const char simple_data_url[] = | 584 const char simple_data_url[] = |
| 609 "data:text/html,<html><head><title>External tab test</title></head>" | 585 "data:text/html,<html><head><title>External tab test</title></head>" |
| 610 "<body>A simple page for testing a floating/invisible tab<br></div>" | 586 "<body>A simple page for testing a floating/invisible tab<br></div>" |
| 611 "</body></html>"; | 587 "</body></html>"; |
| 612 | 588 |
| 613 ExternalTabUITestMockClient::ExternalTabUITestMockClient(int execution_timeout) | 589 ExternalTabUITestMockClient::ExternalTabUITestMockClient(int execution_timeout) |
| 614 : AutomationProxy(execution_timeout), | 590 : AutomationProxy(execution_timeout), |
| (...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1350 #endif | 1326 #endif |
| 1351 TEST_F(AutomationProxyVisibleTest, AutocompleteMatchesTest) { | 1327 TEST_F(AutomationProxyVisibleTest, AutocompleteMatchesTest) { |
| 1352 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 1328 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 1353 ASSERT_TRUE(browser.get()); | 1329 ASSERT_TRUE(browser.get()); |
| 1354 scoped_refptr<AutocompleteEditProxy> edit( | 1330 scoped_refptr<AutocompleteEditProxy> edit( |
| 1355 browser->GetAutocompleteEdit()); | 1331 browser->GetAutocompleteEdit()); |
| 1356 ASSERT_TRUE(edit.get()); | 1332 ASSERT_TRUE(edit.get()); |
| 1357 EXPECT_TRUE(browser->ApplyAccelerator(IDC_FOCUS_LOCATION)); | 1333 EXPECT_TRUE(browser->ApplyAccelerator(IDC_FOCUS_LOCATION)); |
| 1358 EXPECT_TRUE(edit->is_valid()); | 1334 EXPECT_TRUE(edit->is_valid()); |
| 1359 EXPECT_TRUE(edit->SetText(L"Roflcopter")); | 1335 EXPECT_TRUE(edit->SetText(L"Roflcopter")); |
| 1360 EXPECT_TRUE(edit->WaitForQuery(30000)); | 1336 EXPECT_TRUE(edit->WaitForQuery(action_max_timeout_ms())); |
| 1361 bool query_in_progress; | 1337 bool query_in_progress; |
| 1362 EXPECT_TRUE(edit->IsQueryInProgress(&query_in_progress)); | 1338 EXPECT_TRUE(edit->IsQueryInProgress(&query_in_progress)); |
| 1363 EXPECT_FALSE(query_in_progress); | 1339 EXPECT_FALSE(query_in_progress); |
| 1364 std::vector<AutocompleteMatchData> matches; | 1340 std::vector<AutocompleteMatchData> matches; |
| 1365 EXPECT_TRUE(edit->GetAutocompleteMatches(&matches)); | 1341 EXPECT_TRUE(edit->GetAutocompleteMatches(&matches)); |
| 1366 EXPECT_FALSE(matches.empty()); | 1342 EXPECT_FALSE(matches.empty()); |
| 1367 } | 1343 } |
| 1368 | 1344 |
| 1369 // This test is flaky, see http://crbug.com/5314. Disabled because it hangs | 1345 #if defined(OS_MACOSX) |
| 1370 // on Mac (http://crbug.com/25039). | 1346 // Hangs on Mac, http://crbug.com/25039. |
| 1371 TEST_F(AutomationProxyTest, DISABLED_AppModalDialogTest) { | 1347 #define AppModalDialogTest DISABLED_AppModalDialogTest |
| 1348 #else |
| 1349 // Flaky, http://crbug.com/5314. |
| 1350 #define AppModalDialogTest FLAKY_AppModalDialogTest |
| 1351 #endif |
| 1352 TEST_F(AutomationProxyTest, AppModalDialogTest) { |
| 1372 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 1353 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 1373 ASSERT_TRUE(browser.get()); | 1354 ASSERT_TRUE(browser.get()); |
| 1374 scoped_refptr<TabProxy> tab(browser->GetTab(0)); | 1355 scoped_refptr<TabProxy> tab(browser->GetTab(0)); |
| 1375 ASSERT_TRUE(tab.get()); | 1356 ASSERT_TRUE(tab.get()); |
| 1376 | 1357 |
| 1377 bool modal_dialog_showing = false; | 1358 bool modal_dialog_showing = false; |
| 1378 MessageBoxFlags::DialogButton button = MessageBoxFlags::DIALOGBUTTON_NONE; | 1359 MessageBoxFlags::DialogButton button = MessageBoxFlags::DIALOGBUTTON_NONE; |
| 1379 EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing, | 1360 EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing, |
| 1380 &button)); | 1361 &button)); |
| 1381 EXPECT_FALSE(modal_dialog_showing); | 1362 EXPECT_FALSE(modal_dialog_showing); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1473 scoped_refptr<TabProxy> tab(window->GetTab(0)); | 1454 scoped_refptr<TabProxy> tab(window->GetTab(0)); |
| 1474 ASSERT_TRUE(tab.get()); | 1455 ASSERT_TRUE(tab.get()); |
| 1475 | 1456 |
| 1476 FilePath filename(test_data_directory_); | 1457 FilePath filename(test_data_directory_); |
| 1477 filename = filename.AppendASCII("dom_automation_test_with_popup.html"); | 1458 filename = filename.AppendASCII("dom_automation_test_with_popup.html"); |
| 1478 | 1459 |
| 1479 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, | 1460 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, |
| 1480 tab->NavigateToURL(net::FilePathToFileURL(filename))); | 1461 tab->NavigateToURL(net::FilePathToFileURL(filename))); |
| 1481 | 1462 |
| 1482 // Allow some time for the popup to show up and close. | 1463 // Allow some time for the popup to show up and close. |
| 1483 PlatformThread::Sleep(2000); | 1464 PlatformThread::Sleep(sleep_timeout_ms()); |
| 1484 | 1465 |
| 1485 std::wstring expected(L"string"); | 1466 std::wstring expected(L"string"); |
| 1486 std::wstring jscript = CreateJSString(L"\"" + expected + L"\""); | 1467 std::wstring jscript = CreateJSString(L"\"" + expected + L"\""); |
| 1487 std::wstring actual; | 1468 std::wstring actual; |
| 1488 ASSERT_TRUE(tab->ExecuteAndExtractString(L"", jscript, &actual)); | 1469 ASSERT_TRUE(tab->ExecuteAndExtractString(L"", jscript, &actual)); |
| 1489 ASSERT_EQ(expected, actual); | 1470 ASSERT_EQ(expected, actual); |
| 1490 } | 1471 } |
| OLD | NEW |