Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/string_util.h" | |
| 6 #include "base/utf_string_conversions.h" | |
| 7 #include "chrome/browser/ui/browser.h" | |
| 8 #include "chrome/browser/ui/browser_list.h" | |
|
Paweł Hajdan Jr.
2011/06/07 09:46:18
nit: Is this #include needed?
shinyak (Google)
2011/06/07 13:28:48
Done.
| |
| 9 #include "chrome/test/in_process_browser_test.h" | |
| 10 #include "chrome/test/ui_test_utils.h" | |
| 11 #include "content/browser/tab_contents/tab_contents.h" | |
| 12 #include "content/common/notification_type.h" | |
| 13 #include "net/test/test_server.h" | |
| 14 | |
| 15 class ResourceDispatcherHostBrowserTest : public InProcessBrowserTest { | |
| 16 public: | |
| 17 ResourceDispatcherHostBrowserTest() { | |
| 18 EnableDOMAutomation(); | |
| 19 } | |
| 20 | |
| 21 protected: | |
| 22 RenderViewHost* render_view_host() { | |
| 23 return browser()->GetSelectedTabContents()->render_view_host(); | |
| 24 } | |
| 25 | |
| 26 bool GetPopupTitle(const GURL& url, string16* title); | |
| 27 }; | |
| 28 | |
| 29 bool ResourceDispatcherHostBrowserTest::GetPopupTitle(const GURL& url, | |
| 30 string16* title) { | |
| 31 ui_test_utils::NavigateToURL(browser(), url); | |
| 32 | |
| 33 ui_test_utils::WindowedNotificationObserver observer( | |
| 34 NotificationType::BROWSER_WINDOW_READY, | |
| 35 NotificationService::AllSources()); | |
| 36 | |
| 37 // Create dynamic popup. | |
| 38 if (!ui_test_utils::ExecuteJavaScript( | |
| 39 render_view_host(), L"", L"OpenPopup();")) | |
| 40 return false; | |
| 41 | |
| 42 observer.Wait(); | |
| 43 | |
| 44 std::set<Browser*> excluded; | |
| 45 excluded.insert(browser()); | |
| 46 Browser* popup = ui_test_utils::GetBrowserNotInSet(excluded); | |
| 47 if (!popup) | |
| 48 return false; | |
| 49 | |
| 50 *title = popup->GetWindowTitleForCurrentTab(); | |
| 51 return true; | |
| 52 } | |
| 53 | |
| 54 // Test title for content created by javascript window.open(). | |
| 55 // See http://crbug.com/5988 | |
| 56 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, DynamicTitle1) { | |
| 57 ASSERT_TRUE(test_server()->Start()); | |
| 58 | |
| 59 GURL url(test_server()->GetURL("files/dynamic1.html")); | |
| 60 string16 title; | |
| 61 ASSERT_TRUE(GetPopupTitle(url, &title)); | |
| 62 EXPECT_TRUE(StartsWith(title, ASCIIToUTF16("My Popup Title"), false)) | |
|
Paweł Hajdan Jr.
2011/06/07 09:46:18
nit: Are you sure you want a case-insensitive comp
shinyak (Google)
2011/06/07 13:28:48
Done.
| |
| 63 << "Actual title: " << title; | |
| 64 } | |
| 65 | |
| 66 // Test title for content created by javascript window.open(). | |
| 67 // See http://crbug.com/5988 | |
| 68 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, DynamicTitle2) { | |
| 69 ASSERT_TRUE(test_server()->Start()); | |
| 70 | |
| 71 GURL url(test_server()->GetURL("files/dynamic2.html")); | |
| 72 string16 title; | |
| 73 ASSERT_TRUE(GetPopupTitle(url, &title)); | |
| 74 EXPECT_TRUE(StartsWith(title, ASCIIToUTF16("My Dynamic Title"), false)) | |
| 75 << "Actual title: " << title; | |
| 76 } | |
| OLD | NEW |