Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <sstream> | 5 #include <sstream> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" | |
| 12 #include "base/test/test_timeouts.h" | 13 #include "base/test/test_timeouts.h" |
| 13 #include "chrome/browser/net/url_request_failed_dns_job.h" | 14 #include "chrome/browser/net/url_request_failed_dns_job.h" |
| 14 #include "chrome/browser/net/url_request_mock_http_job.h" | 15 #include "chrome/browser/net/url_request_mock_http_job.h" |
| 15 #include "chrome/test/automation/browser_proxy.h" | 16 #include "chrome/test/automation/browser_proxy.h" |
| 16 #include "chrome/test/automation/tab_proxy.h" | 17 #include "chrome/test/automation/tab_proxy.h" |
| 18 #include "chrome/test/automation/window_proxy.h" | |
| 17 #include "chrome/test/ui/ui_test.h" | 19 #include "chrome/test/ui/ui_test.h" |
| 18 #include "content/common/test_url_constants.h" | 20 #include "content/common/test_url_constants.h" |
| 19 #include "content/common/url_constants.h" | 21 #include "content/common/url_constants.h" |
| 22 #include "chrome/test/ui_test_utils.h" | |
|
Paweł Hajdan Jr.
2011/06/01 07:23:44
nit: Is this used?
| |
| 20 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
| 21 #include "net/test/test_server.h" | 24 #include "net/test/test_server.h" |
| 22 | 25 |
| 23 namespace { | 26 namespace { |
| 24 | 27 |
| 25 class ResourceDispatcherTest : public UITest { | 28 class ResourceDispatcherTest : public UITest { |
| 26 public: | 29 public: |
| 27 void CheckTitleTest(const std::string& file, | 30 void CheckTitleTest(const std::string& file, |
| 28 const std::string& expected_title, | 31 const std::string& expected_title, |
| 29 int expected_navigations) { | 32 int expected_navigations) { |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 // Visit a URL that fails without calling ResourceDispatcherHost::Read. | 394 // Visit a URL that fails without calling ResourceDispatcherHost::Read. |
| 392 GURL broken_url("chrome://theme"); | 395 GURL broken_url("chrome://theme"); |
| 393 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(broken_url)); | 396 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(broken_url)); |
| 394 | 397 |
| 395 // Make sure the navigation finishes. | 398 // Make sure the navigation finishes. |
| 396 std::wstring tab_title; | 399 std::wstring tab_title; |
| 397 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); | 400 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); |
| 398 EXPECT_EQ(L"chrome://theme/ is not available", tab_title); | 401 EXPECT_EQ(L"chrome://theme/ is not available", tab_title); |
| 399 } | 402 } |
| 400 | 403 |
| 404 // Test title for content dynamically created by javascript. | |
| 405 // See bug 5988 | |
| 406 TEST_F(ResourceDispatcherTest, DynamicTitle1) { | |
| 407 dom_automation_enabled_ = true; | |
| 408 | |
| 409 net::TestServer test_server(net::TestServer::TYPE_HTTP, | |
| 410 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
| 411 ASSERT_TRUE(test_server.Start()); | |
| 412 | |
| 413 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | |
| 414 ASSERT_TRUE(browser_proxy.get()); | |
| 415 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); | |
| 416 ASSERT_TRUE(tab.get()); | |
| 417 | |
| 418 GURL url(test_server.GetURL("files/dynamic1.html")); | |
| 419 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); | |
| 420 | |
| 421 // Make sure the navigation finishes. | |
| 422 std::wstring tab_title; | |
| 423 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); | |
| 424 | |
| 425 // Create dynamic popup. | |
| 426 std::wstring jscript = | |
| 427 L"OpenPopup(); window.domAutomationController.send('string');"; | |
| 428 std::wstring value; | |
| 429 ASSERT_TRUE(tab->ExecuteAndExtractString(L"", jscript, &value)); | |
| 430 | |
| 431 scoped_refptr<BrowserProxy> browser_proxy2(automation()->GetBrowserWindow(1)); | |
| 432 ASSERT_TRUE(browser_proxy2.get()); | |
| 433 scoped_refptr<WindowProxy> window2(browser_proxy2->GetWindow()); | |
|
Paweł Hajdan Jr.
2011/06/01 07:23:44
WindowProxy are discouraged, do you really need it
| |
| 434 ASSERT_TRUE(window2.get()); | |
| 435 | |
| 436 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms()); | |
|
Paweł Hajdan Jr.
2011/06/01 07:23:44
Are you trying to wait for the load to finish or f
| |
| 437 | |
| 438 string16 tab_title2; | |
| 439 EXPECT_TRUE(window2->GetWindowTitle(&tab_title2)); | |
| 440 | |
| 441 // tab_title3 should start with 'My Dynamic Title' | |
| 442 ASSERT_EQ(string16::size_type(0), | |
| 443 tab_title2.find(ASCIIToUTF16("My Popup Title"))); | |
| 444 } | |
| 445 | |
| 446 // Test title for content dynamically created by javascript. | |
| 447 // See Bug 5988 | |
| 448 TEST_F(ResourceDispatcherTest, DynamicTitle2) { | |
| 449 dom_automation_enabled_ = true; | |
| 450 | |
| 451 net::TestServer test_server(net::TestServer::TYPE_HTTP, | |
| 452 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
| 453 ASSERT_TRUE(test_server.Start()); | |
| 454 | |
| 455 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | |
| 456 ASSERT_TRUE(browser_proxy.get()); | |
| 457 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); | |
| 458 ASSERT_TRUE(tab.get()); | |
| 459 | |
| 460 GURL url(test_server.GetURL("files/dynamic2.html")); | |
| 461 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); | |
| 462 | |
| 463 // Make sure the navigation finishes. | |
| 464 std::wstring tab_title; | |
| 465 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); | |
| 466 | |
| 467 // Create dynamic popup. | |
| 468 std::wstring jscript = | |
| 469 L"OpenPopup(); window.domAutomationController.send('string');"; | |
| 470 std::wstring value; | |
| 471 ASSERT_TRUE(tab->ExecuteAndExtractString(L"", jscript, &value)); | |
| 472 | |
| 473 scoped_refptr<BrowserProxy> browser_proxy2(automation()->GetBrowserWindow(1)); | |
| 474 ASSERT_TRUE(browser_proxy2.get()); | |
| 475 scoped_refptr<WindowProxy> window2(browser_proxy2->GetWindow()); | |
| 476 ASSERT_TRUE(window2.get()); | |
| 477 | |
| 478 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms()); | |
| 479 | |
| 480 string16 tab_title2; | |
| 481 EXPECT_TRUE(window2->GetWindowTitle(&tab_title2)); | |
| 482 | |
| 483 // tab_title3 should start with 'My Dynamic Title' | |
| 484 ASSERT_EQ(string16::size_type(0), | |
| 485 tab_title2.find(ASCIIToUTF16("My Dynamic Title"))); | |
| 486 } | |
| 487 | |
| 401 } // namespace | 488 } // namespace |
| OLD | NEW |