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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "build/build_config.h" |
10 #include "chrome/app/chrome_dll_resource.h" | 11 #include "chrome/app/chrome_dll_resource.h" |
11 #include "chrome/browser/view_ids.h" | 12 #include "chrome/browser/view_ids.h" |
12 #include "chrome/common/chrome_constants.h" | 13 #include "chrome/common/chrome_constants.h" |
13 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/common/json_value_serializer.h" | 15 #include "chrome/common/json_value_serializer.h" |
| 16 #include "chrome/common/message_box_flags.h" |
15 #include "chrome/test/automation/constrained_window_proxy.h" | 17 #include "chrome/test/automation/constrained_window_proxy.h" |
16 #include "chrome/test/automation/browser_proxy.h" | 18 #include "chrome/test/automation/browser_proxy.h" |
17 #include "chrome/test/automation/tab_proxy.h" | 19 #include "chrome/test/automation/tab_proxy.h" |
18 #include "chrome/test/automation/window_proxy.h" | 20 #include "chrome/test/automation/window_proxy.h" |
19 #include "chrome/test/ui/ui_test.h" | 21 #include "chrome/test/ui/ui_test.h" |
20 #include "chrome/views/event.h" | 22 #include "chrome/views/event.h" |
21 #include "chrome/views/window/dialog_delegate.h" | |
22 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
23 | 24 |
24 class AutomationProxyTest : public UITest { | 25 class AutomationProxyTest : public UITest { |
25 protected: | 26 protected: |
26 AutomationProxyTest() { | 27 AutomationProxyTest() { |
27 dom_automation_enabled_ = true; | 28 dom_automation_enabled_ = true; |
28 launch_arguments_.AppendSwitchWithValue(switches::kLang, | 29 launch_arguments_.AppendSwitchWithValue(switches::kLang, |
29 L"en-us"); | 30 L"en-us"); |
30 } | 31 } |
31 }; | 32 }; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(-1)); | 72 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(-1)); |
72 ASSERT_FALSE(window.get()); | 73 ASSERT_FALSE(window.get()); |
73 } | 74 } |
74 | 75 |
75 { | 76 { |
76 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(1)); | 77 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(1)); |
77 ASSERT_FALSE(window.get()); | 78 ASSERT_FALSE(window.get()); |
78 } | 79 } |
79 }; | 80 }; |
80 | 81 |
| 82 // TODO(port): This test is for Chrome Views, which we only use on Windows. |
| 83 // Maybe split this into a _win.cc file? |
| 84 #if defined(OS_WIN) |
81 TEST_F(AutomationProxyVisibleTest, WindowGetViewBounds) { | 85 TEST_F(AutomationProxyVisibleTest, WindowGetViewBounds) { |
82 { | 86 { |
83 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 87 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
84 ASSERT_TRUE(browser.get()); | 88 ASSERT_TRUE(browser.get()); |
85 scoped_ptr<WindowProxy> window(browser->GetWindow()); | 89 scoped_ptr<WindowProxy> window(browser->GetWindow()); |
86 ASSERT_TRUE(window.get()); | 90 ASSERT_TRUE(window.get()); |
87 | 91 |
88 scoped_ptr<TabProxy> tab1(browser->GetTab(0)); | 92 scoped_ptr<TabProxy> tab1(browser->GetTab(0)); |
89 ASSERT_TRUE(tab1.get()); | 93 ASSERT_TRUE(tab1.get()); |
90 GURL tab1_url; | 94 GURL tab1_url; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 ASSERT_TRUE(tab2.get()); | 150 ASSERT_TRUE(tab2.get()); |
147 GURL tab2_new_url; | 151 GURL tab2_new_url; |
148 ASSERT_TRUE(tab2->GetCurrentURL(&tab2_new_url)); | 152 ASSERT_TRUE(tab2->GetCurrentURL(&tab2_new_url)); |
149 | 153 |
150 EXPECT_EQ(tab1_url.spec(), tab2_new_url.spec()); | 154 EXPECT_EQ(tab1_url.spec(), tab2_new_url.spec()); |
151 EXPECT_EQ(tab2_url.spec(), tab1_new_url.spec()); | 155 EXPECT_EQ(tab2_url.spec(), tab1_new_url.spec()); |
152 | 156 |
153 */ | 157 */ |
154 } | 158 } |
155 } | 159 } |
| 160 #endif // defined(OS_WIN) |
156 | 161 |
157 TEST_F(AutomationProxyTest, GetTabCount) { | 162 TEST_F(AutomationProxyTest, GetTabCount) { |
158 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 163 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
159 ASSERT_TRUE(window.get()); | 164 ASSERT_TRUE(window.get()); |
160 | 165 |
161 int tab_count = 0; | 166 int tab_count = 0; |
162 ASSERT_TRUE(window->GetTabCount(&tab_count)); | 167 ASSERT_TRUE(window->GetTabCount(&tab_count)); |
163 ASSERT_EQ(1, tab_count); | 168 ASSERT_EQ(1, tab_count); |
164 } | 169 } |
165 | 170 |
| 171 // TODO(port): Port to mac. |
| 172 #if defined(OS_WIN) || defined(OS_LINUX) |
166 TEST_F(AutomationProxyTest, GetActiveTabIndex) { | 173 TEST_F(AutomationProxyTest, GetActiveTabIndex) { |
167 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 174 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
168 ASSERT_TRUE(window.get()); | 175 ASSERT_TRUE(window.get()); |
169 | 176 |
170 int active_tab_index = -1; | 177 int active_tab_index = -1; |
171 ASSERT_TRUE(window->GetActiveTabIndex(&active_tab_index)); | 178 ASSERT_TRUE(window->GetActiveTabIndex(&active_tab_index)); |
172 ASSERT_EQ(0, active_tab_index); | 179 ASSERT_EQ(0, active_tab_index); |
173 } | 180 } |
| 181 #endif |
174 | 182 |
175 TEST_F(AutomationProxyVisibleTest, AppendTab) { | 183 TEST_F(AutomationProxyVisibleTest, AppendTab) { |
176 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 184 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
177 ASSERT_TRUE(window.get()); | 185 ASSERT_TRUE(window.get()); |
178 | 186 |
179 int original_tab_count; | 187 int original_tab_count; |
180 ASSERT_TRUE(window->GetTabCount(&original_tab_count)); | 188 ASSERT_TRUE(window->GetTabCount(&original_tab_count)); |
181 ASSERT_EQ(1, original_tab_count); // By default there are 2 tabs opened. | 189 ASSERT_EQ(1, original_tab_count); // By default there are 2 tabs opened. |
182 | 190 |
183 int original_active_tab_index; | 191 int original_active_tab_index; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 ASSERT_FALSE(is_timeout); | 296 ASSERT_FALSE(is_timeout); |
289 | 297 |
290 std::wstring title; | 298 std::wstring title; |
291 ASSERT_TRUE(tab->GetTabTitle(&title)); | 299 ASSERT_TRUE(tab->GetTabTitle(&title)); |
292 ASSERT_STREQ(L"Title Of Awesomeness", title.c_str()); | 300 ASSERT_STREQ(L"Title Of Awesomeness", title.c_str()); |
293 | 301 |
294 tab->NavigateToURLWithTimeout(net::FilePathToFileURL(filename), | 302 tab->NavigateToURLWithTimeout(net::FilePathToFileURL(filename), |
295 1, &is_timeout); | 303 1, &is_timeout); |
296 ASSERT_TRUE(is_timeout); | 304 ASSERT_TRUE(is_timeout); |
297 | 305 |
298 Sleep(10); | 306 PlatformThread::Sleep(10); |
299 } | 307 } |
300 | 308 |
301 // This test is disabled. See bug 794412. | 309 // This test is disabled. See bug 794412. |
302 TEST_F(AutomationProxyTest, DISABLED_NavigateToURLWithTimeout2) { | 310 TEST_F(AutomationProxyTest, DISABLED_NavigateToURLWithTimeout2) { |
303 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 311 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
304 ASSERT_TRUE(window.get()); | 312 ASSERT_TRUE(window.get()); |
305 scoped_ptr<TabProxy> tab(window->GetTab(0)); | 313 scoped_ptr<TabProxy> tab(window->GetTab(0)); |
306 tab.reset(window->GetTab(0)); | 314 tab.reset(window->GetTab(0)); |
307 ASSERT_TRUE(tab.get()); | 315 ASSERT_TRUE(tab.get()); |
308 | 316 |
309 FilePath filename1(FilePath::FromWStringHack(test_data_directory_)); | 317 FilePath filename1(FilePath::FromWStringHack(test_data_directory_)); |
310 filename1 = filename1.AppendASCII("title1.html"); | 318 filename1 = filename1.AppendASCII("title1.html"); |
311 | 319 |
312 bool is_timeout; | 320 bool is_timeout; |
313 tab->NavigateToURLWithTimeout(net::FilePathToFileURL(filename1), | 321 tab->NavigateToURLWithTimeout(net::FilePathToFileURL(filename1), |
314 1, &is_timeout); | 322 1, &is_timeout); |
315 ASSERT_TRUE(is_timeout); | 323 ASSERT_TRUE(is_timeout); |
316 | 324 |
317 FilePath filename2(FilePath::FromWStringHack(test_data_directory_)); | 325 FilePath filename2(FilePath::FromWStringHack(test_data_directory_)); |
318 filename2 = filename2.AppendASCII("title1.html"); | 326 filename2 = filename2.AppendASCII("title1.html"); |
319 tab->NavigateToURLWithTimeout(net::FilePathToFileURL(filename2), | 327 tab->NavigateToURLWithTimeout(net::FilePathToFileURL(filename2), |
320 10000, &is_timeout); | 328 10000, &is_timeout); |
321 ASSERT_FALSE(is_timeout); | 329 ASSERT_FALSE(is_timeout); |
322 | 330 |
323 Sleep(10); | 331 PlatformThread::Sleep(10); |
324 } | 332 } |
325 | 333 |
326 TEST_F(AutomationProxyTest, GoBackForward) { | 334 TEST_F(AutomationProxyTest, GoBackForward) { |
327 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 335 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
328 ASSERT_TRUE(window.get()); | 336 ASSERT_TRUE(window.get()); |
329 scoped_ptr<TabProxy> tab(window->GetTab(0)); | 337 scoped_ptr<TabProxy> tab(window->GetTab(0)); |
330 ASSERT_TRUE(tab.get()); | 338 ASSERT_TRUE(tab.get()); |
331 | 339 |
332 std::wstring title; | 340 std::wstring title; |
333 ASSERT_TRUE(tab->GetTabTitle(&title)); | 341 ASSERT_TRUE(tab->GetTabTitle(&title)); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 ASSERT_TRUE(window->GetActiveTabIndex(&active_tab_index)); | 409 ASSERT_TRUE(window->GetActiveTabIndex(&active_tab_index)); |
402 int tab_count; | 410 int tab_count; |
403 ASSERT_TRUE(window->GetTabCount(&tab_count)); | 411 ASSERT_TRUE(window->GetTabCount(&tab_count)); |
404 ASSERT_EQ(0, active_tab_index); | 412 ASSERT_EQ(0, active_tab_index); |
405 int at_index = 1; | 413 int at_index = 1; |
406 ASSERT_TRUE(window->ActivateTab(at_index)); | 414 ASSERT_TRUE(window->ActivateTab(at_index)); |
407 ASSERT_TRUE(window->GetActiveTabIndex(&active_tab_index)); | 415 ASSERT_TRUE(window->GetActiveTabIndex(&active_tab_index)); |
408 ASSERT_EQ(at_index, active_tab_index); | 416 ASSERT_EQ(at_index, active_tab_index); |
409 } | 417 } |
410 | 418 |
| 419 // TODO(port): Port to mac. |
| 420 #if defined(OS_WIN) || defined(OS_LINUX) |
411 TEST_F(AutomationProxyTest2, GetTabTitle) { | 421 TEST_F(AutomationProxyTest2, GetTabTitle) { |
412 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 422 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
413 ASSERT_TRUE(window.get()); | 423 ASSERT_TRUE(window.get()); |
414 scoped_ptr<TabProxy> tab(window->GetTab(0)); | 424 scoped_ptr<TabProxy> tab(window->GetTab(0)); |
415 ASSERT_TRUE(tab.get()); | 425 ASSERT_TRUE(tab.get()); |
416 std::wstring title; | 426 std::wstring title; |
417 ASSERT_TRUE(tab->GetTabTitle(&title)); | 427 ASSERT_TRUE(tab->GetTabTitle(&title)); |
418 ASSERT_STREQ(L"title1.html", title.c_str()); | 428 ASSERT_STREQ(L"title1.html", title.c_str()); |
419 | 429 |
420 tab.reset(window->GetTab(1)); | 430 tab.reset(window->GetTab(1)); |
421 ASSERT_TRUE(tab.get()); | 431 ASSERT_TRUE(tab.get()); |
422 ASSERT_TRUE(tab->GetTabTitle(&title)); | 432 ASSERT_TRUE(tab->GetTabTitle(&title)); |
423 ASSERT_STREQ(L"Title Of Awesomeness", title.c_str()); | 433 ASSERT_STREQ(L"Title Of Awesomeness", title.c_str()); |
424 } | 434 } |
| 435 #endif |
425 | 436 |
426 TEST_F(AutomationProxyTest, Cookies) { | 437 TEST_F(AutomationProxyTest, Cookies) { |
427 GURL url(L"http://mojo.jojo.google.com"); | 438 GURL url("http://mojo.jojo.google.com"); |
428 std::string value_result; | 439 std::string value_result; |
429 | 440 |
430 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 441 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
431 ASSERT_TRUE(window.get()); | 442 ASSERT_TRUE(window.get()); |
432 | 443 |
433 scoped_ptr<TabProxy> tab(window->GetTab(0)); | 444 scoped_ptr<TabProxy> tab(window->GetTab(0)); |
434 ASSERT_TRUE(tab.get()); | 445 ASSERT_TRUE(tab.get()); |
435 | 446 |
436 // test setting the cookie: | 447 // test setting the cookie: |
437 ASSERT_TRUE(tab->SetCookie(url, "foo=baz")); | 448 ASSERT_TRUE(tab->SetCookie(url, "foo=baz")); |
(...skipping 11 matching lines...) Expand all Loading... |
449 // now, test that we can get multiple cookies: | 460 // now, test that we can get multiple cookies: |
450 ASSERT_TRUE(tab->SetCookie(url, "foo1=baz1")); | 461 ASSERT_TRUE(tab->SetCookie(url, "foo1=baz1")); |
451 ASSERT_TRUE(tab->SetCookie(url, "foo2=baz2")); | 462 ASSERT_TRUE(tab->SetCookie(url, "foo2=baz2")); |
452 | 463 |
453 ASSERT_TRUE(tab->GetCookies(url, &value_result)); | 464 ASSERT_TRUE(tab->GetCookies(url, &value_result)); |
454 ASSERT_FALSE(value_result.empty()); | 465 ASSERT_FALSE(value_result.empty()); |
455 EXPECT_TRUE(value_result.find("foo1=baz1") != std::string::npos); | 466 EXPECT_TRUE(value_result.find("foo1=baz1") != std::string::npos); |
456 EXPECT_TRUE(value_result.find("foo2=baz2") != std::string::npos); | 467 EXPECT_TRUE(value_result.find("foo2=baz2") != std::string::npos); |
457 } | 468 } |
458 | 469 |
| 470 // TODO(port): Determine what tests need this and port. |
| 471 #if defined(OS_WIN) |
459 TEST_F(AutomationProxyTest, GetHWND) { | 472 TEST_F(AutomationProxyTest, GetHWND) { |
460 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 473 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
461 ASSERT_TRUE(browser.get()); | 474 ASSERT_TRUE(browser.get()); |
462 scoped_ptr<WindowProxy> window(browser->GetWindow()); | 475 scoped_ptr<WindowProxy> window(browser->GetWindow()); |
463 ASSERT_TRUE(window.get()); | 476 ASSERT_TRUE(window.get()); |
464 | 477 |
465 HWND handle; | 478 HWND handle; |
466 ASSERT_TRUE(window->GetHWND(&handle)); | 479 ASSERT_TRUE(window->GetHWND(&handle)); |
467 ASSERT_TRUE(handle); | 480 ASSERT_TRUE(handle); |
468 } | 481 } |
| 482 #endif |
469 | 483 |
470 TEST_F(AutomationProxyTest, NavigateToURLAsync) { | 484 TEST_F(AutomationProxyTest, NavigateToURLAsync) { |
471 AutomationProxy* automation_object = automation(); | 485 AutomationProxy* automation_object = automation(); |
472 scoped_ptr<BrowserProxy> window(automation_object->GetBrowserWindow(0)); | 486 scoped_ptr<BrowserProxy> window(automation_object->GetBrowserWindow(0)); |
473 ASSERT_TRUE(window.get()); | 487 ASSERT_TRUE(window.get()); |
474 scoped_ptr<TabProxy> tab(window->GetTab(0)); | 488 scoped_ptr<TabProxy> tab(window->GetTab(0)); |
475 ASSERT_TRUE(tab.get()); | 489 ASSERT_TRUE(tab.get()); |
476 | 490 |
477 FilePath filename(FilePath::FromWStringHack(test_data_directory_)); | 491 FilePath filename(FilePath::FromWStringHack(test_data_directory_)); |
478 filename = filename.AppendASCII("cookie1.html"); | 492 filename = filename.AppendASCII("cookie1.html"); |
(...skipping 14 matching lines...) Expand all Loading... |
493 ASSERT_TRUE(window->ApplyAccelerator(IDC_NEW_TAB)); | 507 ASSERT_TRUE(window->ApplyAccelerator(IDC_NEW_TAB)); |
494 ASSERT_TRUE(window->WaitForTabCountToBecome(tab_count + 1, | 508 ASSERT_TRUE(window->WaitForTabCountToBecome(tab_count + 1, |
495 action_timeout_ms())); | 509 action_timeout_ms())); |
496 ASSERT_TRUE(window->GetTabCount(&tab_count)); | 510 ASSERT_TRUE(window->GetTabCount(&tab_count)); |
497 scoped_ptr<TabProxy> tab(window->GetTab(tab_count - 1)); | 511 scoped_ptr<TabProxy> tab(window->GetTab(tab_count - 1)); |
498 ASSERT_TRUE(tab.get()); | 512 ASSERT_TRUE(tab.get()); |
499 | 513 |
500 std::wstring title; | 514 std::wstring title; |
501 int i; | 515 int i; |
502 for (i = 0; i < 10; ++i) { | 516 for (i = 0; i < 10; ++i) { |
503 Sleep(sleep_timeout_ms()); | 517 PlatformThread::Sleep(sleep_timeout_ms()); |
504 ASSERT_TRUE(tab->GetTabTitle(&title)); | 518 ASSERT_TRUE(tab->GetTabTitle(&title)); |
505 if (title == L"Destinations" || title == L"New Tab") | 519 if (title == L"Destinations" || title == L"New Tab") |
506 break; | 520 break; |
507 } | 521 } |
508 // If we got to 10, the new tab failed to open. | 522 // If we got to 10, the new tab failed to open. |
509 ASSERT_NE(10, i); | 523 ASSERT_NE(10, i); |
510 } | 524 } |
511 | 525 |
512 class AutomationProxyTest4 : public UITest { | 526 class AutomationProxyTest4 : public UITest { |
513 protected: | 527 protected: |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 std::wstring document1_; | 608 std::wstring document1_; |
595 }; | 609 }; |
596 | 610 |
597 std::wstring CreateJSStringForDOMQuery(const std::wstring& id) { | 611 std::wstring CreateJSStringForDOMQuery(const std::wstring& id) { |
598 std::wstring jscript(L"window.domAutomationController"); | 612 std::wstring jscript(L"window.domAutomationController"); |
599 StringAppendF(&jscript, L".send(document.getElementById('%ls').nodeName);", | 613 StringAppendF(&jscript, L".send(document.getElementById('%ls').nodeName);", |
600 id.c_str()); | 614 id.c_str()); |
601 return jscript; | 615 return jscript; |
602 } | 616 } |
603 | 617 |
| 618 // TODO(port): Port to mac. |
| 619 #if defined(OS_WIN) || defined(OS_LINUX) |
604 TEST_F(AutomationProxyTest3, FrameDocumentCanBeAccessed) { | 620 TEST_F(AutomationProxyTest3, FrameDocumentCanBeAccessed) { |
605 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 621 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
606 ASSERT_TRUE(window.get()); | 622 ASSERT_TRUE(window.get()); |
607 | 623 |
608 scoped_ptr<TabProxy> tab(window->GetTab(0)); | 624 scoped_ptr<TabProxy> tab(window->GetTab(0)); |
609 ASSERT_TRUE(tab.get()); | 625 ASSERT_TRUE(tab.get()); |
610 | 626 |
611 std::wstring actual; | 627 std::wstring actual; |
612 std::wstring xpath1 = L""; // top level frame | 628 std::wstring xpath1 = L""; // top level frame |
613 std::wstring jscript1 = CreateJSStringForDOMQuery(L"myinput"); | 629 std::wstring jscript1 = CreateJSStringForDOMQuery(L"myinput"); |
(...skipping 17 matching lines...) Expand all Loading... |
631 #if 0 | 647 #if 0 |
632 // Open a new Destinations tab to execute script inside. | 648 // Open a new Destinations tab to execute script inside. |
633 window->ApplyAccelerator(IDC_NEWTAB); | 649 window->ApplyAccelerator(IDC_NEWTAB); |
634 tab.reset(window->GetTab(1)); | 650 tab.reset(window->GetTab(1)); |
635 ASSERT_TRUE(tab.get()); | 651 ASSERT_TRUE(tab.get()); |
636 ASSERT_TRUE(window->ActivateTab(1)); | 652 ASSERT_TRUE(window->ActivateTab(1)); |
637 | 653 |
638 std::wstring title; | 654 std::wstring title; |
639 int i; | 655 int i; |
640 for (i = 0; i < 10; ++i) { | 656 for (i = 0; i < 10; ++i) { |
641 Sleep(sleep_timeout_ms()); | 657 PlatformThread::Sleep(sleep_timeout_ms()); |
642 ASSERT_TRUE(tab->GetTabTitle(&title)); | 658 ASSERT_TRUE(tab->GetTabTitle(&title)); |
643 if (title == L"Destinations") | 659 if (title == L"Destinations") |
644 break; | 660 break; |
645 } | 661 } |
646 // If we got to 10, the new tab failed to open. | 662 // If we got to 10, the new tab failed to open. |
647 ASSERT_NE(10, i); | 663 ASSERT_NE(10, i); |
648 ASSERT_FALSE(tab->ExecuteAndExtractString(xpath1, jscript1, &actual)); | 664 ASSERT_FALSE(tab->ExecuteAndExtractString(xpath1, jscript1, &actual)); |
649 #endif | 665 #endif |
650 } | 666 } |
| 667 #endif // defined(OS_WIN) || defined(OS_LINUX) |
651 | 668 |
| 669 // TODO(port): Need to port constrained_window_proxy.* first. |
| 670 #if defined(OS_WIN) |
652 TEST_F(AutomationProxyTest, DISABLED_ConstrainedWindowTest) { | 671 TEST_F(AutomationProxyTest, DISABLED_ConstrainedWindowTest) { |
653 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 672 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
654 ASSERT_TRUE(window.get()); | 673 ASSERT_TRUE(window.get()); |
655 | 674 |
656 scoped_ptr<TabProxy> tab(window->GetTab(0)); | 675 scoped_ptr<TabProxy> tab(window->GetTab(0)); |
657 tab.reset(window->GetTab(0)); | 676 tab.reset(window->GetTab(0)); |
658 ASSERT_TRUE(tab.get()); | 677 ASSERT_TRUE(tab.get()); |
659 | 678 |
660 FilePath filename(FilePath::FromWStringHack(test_data_directory_)); | 679 FilePath filename(FilePath::FromWStringHack(test_data_directory_)); |
661 filename = filename.AppendASCII("constrained_files"); | 680 filename = filename.AppendASCII("constrained_files"); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 ConstrainedWindowProxy* cwindow = tab->GetConstrainedWindow(0); | 731 ConstrainedWindowProxy* cwindow = tab->GetConstrainedWindow(0); |
713 ASSERT_TRUE(cwindow); | 732 ASSERT_TRUE(cwindow); |
714 | 733 |
715 gfx::Rect rect; | 734 gfx::Rect rect; |
716 bool is_timeout = false; | 735 bool is_timeout = false; |
717 ASSERT_TRUE(cwindow->GetBoundsWithTimeout(&rect, 1000, &is_timeout)); | 736 ASSERT_TRUE(cwindow->GetBoundsWithTimeout(&rect, 1000, &is_timeout)); |
718 ASSERT_FALSE(is_timeout); | 737 ASSERT_FALSE(is_timeout); |
719 ASSERT_NE(20, rect.x()); | 738 ASSERT_NE(20, rect.x()); |
720 ASSERT_NE(20, rect.y()); | 739 ASSERT_NE(20, rect.y()); |
721 } | 740 } |
| 741 #endif // defined(OS_WIN) |
722 | 742 |
| 743 |
| 744 // TODO(port): Remove HWND if possible. |
| 745 #if defined(OS_WIN) |
723 // Creates a top-level window, makes the |external_tab_window| a child | 746 // Creates a top-level window, makes the |external_tab_window| a child |
724 // of that window and displays them. After displaying the windows the function | 747 // of that window and displays them. After displaying the windows the function |
725 // enters a message loop that processes window messages as well as calling | 748 // enters a message loop that processes window messages as well as calling |
726 // MessageLoop::current()->RunAllPending() to process any incoming IPC messages. | 749 // MessageLoop::current()->RunAllPending() to process any incoming IPC messages. |
727 // The time_to_wait parameter is the maximum time the loop will run. | 750 // The time_to_wait parameter is the maximum time the loop will run. |
728 // To end the loop earlier, post a quit message to the thread. | 751 // To end the loop earlier, post a quit message to the thread. |
729 bool ExternalTabHandler(HWND external_tab_window, int time_to_wait) { | 752 bool ExternalTabHandler(HWND external_tab_window, int time_to_wait) { |
730 static const wchar_t class_name[] = L"External_Tab_UI_Test_Class"; | 753 static const wchar_t class_name[] = L"External_Tab_UI_Test_Class"; |
731 static const wchar_t window_title[] = L"External Tab Tester"; | 754 static const wchar_t window_title[] = L"External Tab Tester"; |
732 | 755 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 | 857 |
835 const std::string& target() const { | 858 const std::string& target() const { |
836 return target_; | 859 return target_; |
837 } | 860 } |
838 | 861 |
839 // Waits for the DidNavigate event to be processed on the current thread. | 862 // Waits for the DidNavigate event to be processed on the current thread. |
840 // Returns true if the event arrived, false if there was a timeout. | 863 // Returns true if the event arrived, false if there was a timeout. |
841 bool WaitForNavigationComplete(int max_time_to_wait_ms) { | 864 bool WaitForNavigationComplete(int max_time_to_wait_ms) { |
842 base::TimeTicks start(base::TimeTicks::Now()); | 865 base::TimeTicks start(base::TimeTicks::Now()); |
843 while (!navigate_complete_) { | 866 while (!navigate_complete_) { |
844 Sleep(50); | 867 PlatformThread::Sleep(50); |
845 MessageLoop::current()->RunAllPending(); | 868 MessageLoop::current()->RunAllPending(); |
846 base::TimeTicks end(base::TimeTicks::Now()); | 869 base::TimeTicks end(base::TimeTicks::Now()); |
847 base::TimeDelta delta = end - start; | 870 base::TimeDelta delta = end - start; |
848 if (static_cast<int>(delta.InMilliseconds()) > max_time_to_wait_ms) | 871 if (static_cast<int>(delta.InMilliseconds()) > max_time_to_wait_ms) |
849 return false; | 872 return false; |
850 } | 873 } |
851 return true; | 874 return true; |
852 } | 875 } |
853 | 876 |
854 protected: | 877 protected: |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 TEST_F(ExternalTabTestType, CreateExternalTab) { | 910 TEST_F(ExternalTabTestType, CreateExternalTab) { |
888 HWND external_tab_container = NULL; | 911 HWND external_tab_container = NULL; |
889 scoped_ptr<TabProxy> tab(automation()->CreateExternalTab(NULL, gfx::Rect(), | 912 scoped_ptr<TabProxy> tab(automation()->CreateExternalTab(NULL, gfx::Rect(), |
890 WS_POPUP, false, &external_tab_container)); | 913 WS_POPUP, false, &external_tab_container)); |
891 EXPECT_TRUE(tab != NULL); | 914 EXPECT_TRUE(tab != NULL); |
892 EXPECT_NE(FALSE, ::IsWindow(external_tab_container)); | 915 EXPECT_NE(FALSE, ::IsWindow(external_tab_container)); |
893 if (tab != NULL) { | 916 if (tab != NULL) { |
894 tab->NavigateInExternalTab(GURL(L"http://www.google.com")); | 917 tab->NavigateInExternalTab(GURL(L"http://www.google.com")); |
895 EXPECT_EQ(true, ExternalTabHandler(external_tab_container, 1000)); | 918 EXPECT_EQ(true, ExternalTabHandler(external_tab_container, 1000)); |
896 // Since the tab goes away lazily, wait a bit | 919 // Since the tab goes away lazily, wait a bit |
897 Sleep(1000); | 920 PlatformThread::Sleep(1000); |
898 EXPECT_FALSE(tab->is_valid()); | 921 EXPECT_FALSE(tab->is_valid()); |
899 } | 922 } |
900 } | 923 } |
901 | 924 |
902 TEST_F(ExternalTabTestType, IncognitoMode) { | 925 TEST_F(ExternalTabTestType, IncognitoMode) { |
903 HWND external_tab_container = NULL; | 926 HWND external_tab_container = NULL; |
904 GURL url(L"http://anatomyofmelancholy.net"); | 927 GURL url("http://anatomyofmelancholy.net"); |
905 std::string value_result; | 928 std::string value_result; |
906 | 929 |
907 // Create incognito tab | 930 // Create incognito tab |
908 scoped_ptr<TabProxy> tab(automation()->CreateExternalTab(NULL, gfx::Rect(), | 931 scoped_ptr<TabProxy> tab(automation()->CreateExternalTab(NULL, gfx::Rect(), |
909 WS_POPUP, true, &external_tab_container)); | 932 WS_POPUP, true, &external_tab_container)); |
910 EXPECT_TRUE(tab->SetCookie(url, "robert=burton; " | 933 EXPECT_TRUE(tab->SetCookie(url, "robert=burton; " |
911 "expires=Thu, 13 Oct 2011 05:04:03 UTC;")); | 934 "expires=Thu, 13 Oct 2011 05:04:03 UTC;")); |
912 EXPECT_TRUE(tab->GetCookieByName(url, "robert", &value_result)); | 935 EXPECT_TRUE(tab->GetCookieByName(url, "robert", &value_result)); |
913 EXPECT_EQ("burton", value_result); | 936 EXPECT_EQ("burton", value_result); |
914 tab.reset(NULL); | 937 tab.reset(NULL); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 "null", "*"); | 975 "null", "*"); |
953 | 976 |
954 EXPECT_TRUE(ExternalTabHandler(external_tab_container, 10000)); | 977 EXPECT_TRUE(ExternalTabHandler(external_tab_container, 10000)); |
955 EXPECT_NE(0, proxy->messages_received()); | 978 EXPECT_NE(0, proxy->messages_received()); |
956 | 979 |
957 if (proxy->messages_received()) { | 980 if (proxy->messages_received()) { |
958 EXPECT_EQ("Hello from gtest", proxy->message()); | 981 EXPECT_EQ("Hello from gtest", proxy->message()); |
959 } | 982 } |
960 } | 983 } |
961 } | 984 } |
| 985 #endif // defined(OS_WIN) |
962 | 986 |
| 987 // TODO(port): Need to port autocomplete_edit_proxy.* first. |
| 988 #if defined(OS_WIN) |
963 TEST_F(AutomationProxyTest, AutocompleteGetSetText) { | 989 TEST_F(AutomationProxyTest, AutocompleteGetSetText) { |
964 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 990 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
965 ASSERT_TRUE(browser.get()); | 991 ASSERT_TRUE(browser.get()); |
966 scoped_ptr<AutocompleteEditProxy> edit( | 992 scoped_ptr<AutocompleteEditProxy> edit( |
967 browser->GetAutocompleteEdit()); | 993 browser->GetAutocompleteEdit()); |
968 ASSERT_TRUE(edit.get()); | 994 ASSERT_TRUE(edit.get()); |
969 EXPECT_TRUE(edit->is_valid()); | 995 EXPECT_TRUE(edit->is_valid()); |
970 const std::wstring text_to_set = L"Lollerskates"; | 996 const std::wstring text_to_set = L"Lollerskates"; |
971 std::wstring actual_text; | 997 std::wstring actual_text; |
972 EXPECT_TRUE(edit->SetText(text_to_set)); | 998 EXPECT_TRUE(edit->SetText(text_to_set)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 EXPECT_TRUE(edit->is_valid()); | 1039 EXPECT_TRUE(edit->is_valid()); |
1014 EXPECT_TRUE(edit->SetText(L"Roflcopter")); | 1040 EXPECT_TRUE(edit->SetText(L"Roflcopter")); |
1015 EXPECT_TRUE(edit->WaitForQuery(30000)); | 1041 EXPECT_TRUE(edit->WaitForQuery(30000)); |
1016 bool query_in_progress; | 1042 bool query_in_progress; |
1017 EXPECT_TRUE(edit->IsQueryInProgress(&query_in_progress)); | 1043 EXPECT_TRUE(edit->IsQueryInProgress(&query_in_progress)); |
1018 EXPECT_FALSE(query_in_progress); | 1044 EXPECT_FALSE(query_in_progress); |
1019 std::vector<AutocompleteMatchData> matches; | 1045 std::vector<AutocompleteMatchData> matches; |
1020 EXPECT_TRUE(edit->GetAutocompleteMatches(&matches)); | 1046 EXPECT_TRUE(edit->GetAutocompleteMatches(&matches)); |
1021 EXPECT_FALSE(matches.empty()); | 1047 EXPECT_FALSE(matches.empty()); |
1022 } | 1048 } |
| 1049 #endif // defined(OS_WIN) |
1023 | 1050 |
1024 // Disabled because flacky see bug #5314. | 1051 // Disabled because flaky see bug #5314. |
1025 TEST_F(AutomationProxyTest, DISABLED_AppModalDialogTest) { | 1052 TEST_F(AutomationProxyTest, DISABLED_AppModalDialogTest) { |
1026 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 1053 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
1027 ASSERT_TRUE(browser.get()); | 1054 ASSERT_TRUE(browser.get()); |
1028 scoped_ptr<TabProxy> tab(browser->GetTab(0)); | 1055 scoped_ptr<TabProxy> tab(browser->GetTab(0)); |
1029 tab.reset(browser->GetTab(0)); | 1056 tab.reset(browser->GetTab(0)); |
1030 ASSERT_TRUE(tab.get()); | 1057 ASSERT_TRUE(tab.get()); |
1031 | 1058 |
1032 bool modal_dialog_showing = false; | 1059 bool modal_dialog_showing = false; |
1033 MessageBoxFlags::DialogButton button = MessageBoxFlags::DIALOGBUTTON_NONE; | 1060 MessageBoxFlags::DialogButton button = MessageBoxFlags::DIALOGBUTTON_NONE; |
1034 EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing, | 1061 EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 | 1151 |
1125 scoped_ptr<TabProxy> tab(window->GetTab(0)); | 1152 scoped_ptr<TabProxy> tab(window->GetTab(0)); |
1126 ASSERT_TRUE(tab.get()); | 1153 ASSERT_TRUE(tab.get()); |
1127 | 1154 |
1128 FilePath filename(FilePath::FromWStringHack(test_data_directory_)); | 1155 FilePath filename(FilePath::FromWStringHack(test_data_directory_)); |
1129 filename = filename.AppendASCII("dom_automation_test_with_popup.html"); | 1156 filename = filename.AppendASCII("dom_automation_test_with_popup.html"); |
1130 | 1157 |
1131 tab->NavigateToURL(net::FilePathToFileURL(filename)); | 1158 tab->NavigateToURL(net::FilePathToFileURL(filename)); |
1132 | 1159 |
1133 // Allow some time for the popup to show up and close. | 1160 // Allow some time for the popup to show up and close. |
1134 Sleep(2000); | 1161 PlatformThread::Sleep(2000); |
1135 | 1162 |
1136 std::wstring expected(L"string"); | 1163 std::wstring expected(L"string"); |
1137 std::wstring jscript = CreateJSString(L"\"" + expected + L"\""); | 1164 std::wstring jscript = CreateJSString(L"\"" + expected + L"\""); |
1138 std::wstring actual; | 1165 std::wstring actual; |
1139 ASSERT_TRUE(tab->ExecuteAndExtractString(L"", jscript, &actual)); | 1166 ASSERT_TRUE(tab->ExecuteAndExtractString(L"", jscript, &actual)); |
1140 ASSERT_STREQ(expected.c_str(), actual.c_str()); | 1167 ASSERT_STREQ(expected.c_str(), actual.c_str()); |
1141 } | 1168 } |
OLD | NEW |