OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/test/ui/ui_test.h" | 5 #include "chrome/test/ui/ui_test.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "chrome/app/chrome_dll_resource.h" | 8 #include "chrome/app/chrome_dll_resource.h" |
9 #include "chrome/browser/dom_ui/new_tab_ui.h" | 9 #include "chrome/browser/dom_ui/new_tab_ui.h" |
10 #include "chrome/browser/pref_service.h" | 10 #include "chrome/browser/pref_service.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 UITest::DEFAULT_THEME)); | 26 UITest::DEFAULT_THEME)); |
27 } | 27 } |
28 }; | 28 }; |
29 | 29 |
30 TEST_F(NewTabUITest, NTPHasThumbnails) { | 30 TEST_F(NewTabUITest, NTPHasThumbnails) { |
31 // Switch to the "new tab" tab, which should be any new tab after the | 31 // Switch to the "new tab" tab, which should be any new tab after the |
32 // first (the first is about:blank). | 32 // first (the first is about:blank). |
33 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 33 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
34 ASSERT_TRUE(window.get()); | 34 ASSERT_TRUE(window.get()); |
35 | 35 |
36 int tab_count = -1; | |
37 ASSERT_TRUE(window->GetTabCount(&tab_count)); | |
38 ASSERT_EQ(1, tab_count); | |
39 | |
40 // Bring up a new tab page. | 36 // Bring up a new tab page. |
41 ASSERT_TRUE(window->RunCommand(IDC_NEW_TAB)); | 37 ASSERT_TRUE(window->RunCommand(IDC_NEW_TAB)); |
42 ASSERT_TRUE(window->GetTabCount(&tab_count)); | |
43 ASSERT_EQ(2, tab_count); | |
44 int load_time; | 38 int load_time; |
45 ASSERT_TRUE(automation()->WaitForInitialNewTabUILoad(&load_time)); | 39 ASSERT_TRUE(automation()->WaitForInitialNewTabUILoad(&load_time)); |
46 | 40 |
47 // Blank thumbnails on the NTP have the class 'filler' applied to the div. | 41 // Blank thumbnails on the NTP have the class 'filler' applied to the div. |
48 // If all the thumbnails load, there should be no div's with 'filler'. | 42 // If all the thumbnails load, there should be no div's with 'filler'. |
49 scoped_refptr<TabProxy> tab = window->GetActiveTab(); | 43 scoped_refptr<TabProxy> tab = window->GetActiveTab(); |
50 ASSERT_TRUE(tab.get()); | 44 ASSERT_TRUE(tab.get()); |
51 | 45 |
52 int filler_thumbnails_count = -1; | 46 int filler_thumbnails_count = -1; |
53 const int kWaitDuration = 100; | |
54 int wait_time = action_max_timeout_ms(); | 47 int wait_time = action_max_timeout_ms(); |
55 while (wait_time > 0) { | 48 while (wait_time > 0) { |
56 ASSERT_TRUE(tab->ExecuteAndExtractInt(L"", | 49 ASSERT_TRUE(tab->ExecuteAndExtractInt(L"", |
57 L"window.domAutomationController.send(" | 50 L"window.domAutomationController.send(" |
58 L"document.getElementsByClassName('filler').length)", | 51 L"document.getElementsByClassName('filler').length)", |
59 &filler_thumbnails_count)); | 52 &filler_thumbnails_count)); |
60 if (filler_thumbnails_count == 0) | 53 if (filler_thumbnails_count == 0) |
61 break; | 54 break; |
62 PlatformThread::Sleep(kWaitDuration); | 55 PlatformThread::Sleep(sleep_timeout_ms()); |
63 wait_time -= kWaitDuration; | 56 wait_time -= sleep_timeout_ms(); |
64 } | 57 } |
65 EXPECT_EQ(0, filler_thumbnails_count); | 58 EXPECT_EQ(0, filler_thumbnails_count); |
66 } | 59 } |
67 | 60 |
68 TEST_F(NewTabUITest, ChromeInternalLoadsNTP) { | 61 TEST_F(NewTabUITest, ChromeInternalLoadsNTP) { |
69 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 62 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
70 ASSERT_TRUE(window.get()); | 63 ASSERT_TRUE(window.get()); |
71 | 64 |
72 int tab_count = -1; | |
73 ASSERT_TRUE(window->GetTabCount(&tab_count)); | |
74 ASSERT_EQ(1, tab_count); | |
75 | |
76 // Go to the "new tab page" using its old url, rather than chrome://newtab. | 65 // Go to the "new tab page" using its old url, rather than chrome://newtab. |
77 scoped_refptr<TabProxy> tab = window->GetTab(0); | 66 scoped_refptr<TabProxy> tab = window->GetTab(0); |
78 ASSERT_TRUE(tab.get()); | 67 ASSERT_TRUE(tab.get()); |
79 ASSERT_TRUE(tab->NavigateToURLAsync(GURL("chrome-internal:"))); | 68 ASSERT_TRUE(tab->NavigateToURLAsync(GURL("chrome-internal:"))); |
80 int load_time; | 69 int load_time; |
81 ASSERT_TRUE(automation()->WaitForInitialNewTabUILoad(&load_time)); | 70 ASSERT_TRUE(automation()->WaitForInitialNewTabUILoad(&load_time)); |
82 | 71 |
83 // Ensure there are some thumbnails loaded in the page. | 72 // Ensure there are some thumbnails loaded in the page. |
84 int thumbnails_count = -1; | 73 int thumbnails_count = -1; |
85 ASSERT_TRUE(tab->ExecuteAndExtractInt(L"", | 74 ASSERT_TRUE(tab->ExecuteAndExtractInt(L"", |
(...skipping 25 matching lines...) Expand all Loading... |
111 ASSERT_FALSE(migrated); | 100 ASSERT_FALSE(migrated); |
112 } | 101 } |
113 | 102 |
114 TEST_F(NewTabUITest, HomePageLink) { | 103 TEST_F(NewTabUITest, HomePageLink) { |
115 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 104 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
116 ASSERT_TRUE(browser.get()); | 105 ASSERT_TRUE(browser.get()); |
117 | 106 |
118 ASSERT_TRUE( | 107 ASSERT_TRUE( |
119 browser->SetBooleanPreference(prefs::kHomePageIsNewTabPage, false)); | 108 browser->SetBooleanPreference(prefs::kHomePageIsNewTabPage, false)); |
120 | 109 |
121 int tab_count = -1; | |
122 ASSERT_TRUE(browser->GetTabCount(&tab_count)); | |
123 ASSERT_EQ(1, tab_count); | |
124 | |
125 // Bring up a new tab page. | 110 // Bring up a new tab page. |
126 ASSERT_TRUE(browser->RunCommand(IDC_NEW_TAB)); | 111 ASSERT_TRUE(browser->RunCommand(IDC_NEW_TAB)); |
127 ASSERT_TRUE(browser->GetTabCount(&tab_count)); | |
128 ASSERT_EQ(2, tab_count); | |
129 int load_time; | 112 int load_time; |
130 ASSERT_TRUE(automation()->WaitForInitialNewTabUILoad(&load_time)); | 113 ASSERT_TRUE(automation()->WaitForInitialNewTabUILoad(&load_time)); |
131 | 114 |
132 scoped_refptr<TabProxy> tab = browser->GetActiveTab(); | 115 scoped_refptr<TabProxy> tab = browser->GetActiveTab(); |
133 ASSERT_TRUE(tab.get()); | 116 ASSERT_TRUE(tab.get()); |
134 | 117 |
135 // TODO(arv): Extract common patterns for doing js testing. | 118 // TODO(arv): Extract common patterns for doing js testing. |
136 | 119 |
137 // Fire click. Because tip service is turned off for testing, we first | 120 // Fire click. Because tip service is turned off for testing, we first |
138 // force the "make this my home page" tip to appear. | 121 // force the "make this my home page" tip to appear. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 L"})()" | 159 L"})()" |
177 L")", | 160 L")", |
178 &has_class)); | 161 &has_class)); |
179 ASSERT_TRUE(has_class); | 162 ASSERT_TRUE(has_class); |
180 | 163 |
181 bool is_home_page; | 164 bool is_home_page; |
182 ASSERT_TRUE(browser->GetBooleanPreference(prefs::kHomePageIsNewTabPage, | 165 ASSERT_TRUE(browser->GetBooleanPreference(prefs::kHomePageIsNewTabPage, |
183 &is_home_page)); | 166 &is_home_page)); |
184 ASSERT_TRUE(is_home_page); | 167 ASSERT_TRUE(is_home_page); |
185 } | 168 } |
OLD | NEW |