| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/chrome_thread.h" | 9 #include "chrome/browser/chrome_thread.h" |
| 10 #include "chrome/browser/dom_ui/new_tab_ui.h" | 10 #include "chrome/browser/dom_ui/new_tab_ui.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 ASSERT_EQ(0, prefs->GetInteger(prefs::kNTPPrefVersion)); | 88 ASSERT_EQ(0, prefs->GetInteger(prefs::kNTPPrefVersion)); |
| 89 | 89 |
| 90 bool migrated = NewTabUI::UpdateUserPrefsVersion(prefs.get()); | 90 bool migrated = NewTabUI::UpdateUserPrefsVersion(prefs.get()); |
| 91 ASSERT_TRUE(migrated); | 91 ASSERT_TRUE(migrated); |
| 92 ASSERT_EQ(NewTabUI::current_pref_version(), | 92 ASSERT_EQ(NewTabUI::current_pref_version(), |
| 93 prefs->GetInteger(prefs::kNTPPrefVersion)); | 93 prefs->GetInteger(prefs::kNTPPrefVersion)); |
| 94 | 94 |
| 95 migrated = NewTabUI::UpdateUserPrefsVersion(prefs.get()); | 95 migrated = NewTabUI::UpdateUserPrefsVersion(prefs.get()); |
| 96 ASSERT_FALSE(migrated); | 96 ASSERT_FALSE(migrated); |
| 97 } | 97 } |
| 98 | |
| 99 TEST_F(NewTabUITest, HomePageLink) { | |
| 100 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | |
| 101 ASSERT_TRUE(browser.get()); | |
| 102 | |
| 103 ASSERT_TRUE( | |
| 104 browser->SetBooleanPreference(prefs::kHomePageIsNewTabPage, false)); | |
| 105 | |
| 106 // Bring up a new tab page. | |
| 107 ASSERT_TRUE(browser->RunCommand(IDC_NEW_TAB)); | |
| 108 int load_time; | |
| 109 ASSERT_TRUE(automation()->WaitForInitialNewTabUILoad(&load_time)); | |
| 110 | |
| 111 scoped_refptr<TabProxy> tab = browser->GetActiveTab(); | |
| 112 ASSERT_TRUE(tab.get()); | |
| 113 | |
| 114 // TODO(arv): Extract common patterns for doing js testing. | |
| 115 | |
| 116 // Fire click. Because tip service is turned off for testing, we first | |
| 117 // force the "make this my home page" tip to appear. | |
| 118 // TODO(arv): Find screen position of element and use a lower level click | |
| 119 // emulation. | |
| 120 bool result; | |
| 121 ASSERT_TRUE(tab->ExecuteAndExtractBool(L"", | |
| 122 L"window.domAutomationController.send(" | |
| 123 L"(function() {" | |
| 124 L" tipCache = [{\"set_homepage_tip\":\"Make this the home page\"}];" | |
| 125 L" renderTip();" | |
| 126 L" var e = document.createEvent('Event');" | |
| 127 L" e.initEvent('click', true, true);" | |
| 128 L" var el = document.querySelector('#tip-line > button');" | |
| 129 L" el.dispatchEvent(e);" | |
| 130 L" return true;" | |
| 131 L"})()" | |
| 132 L")", | |
| 133 &result)); | |
| 134 ASSERT_TRUE(result); | |
| 135 | |
| 136 // Make sure text of "set as home page" tip has been removed. | |
| 137 std::wstring tip_text_content; | |
| 138 ASSERT_TRUE(tab->ExecuteAndExtractString(L"", | |
| 139 L"window.domAutomationController.send(" | |
| 140 L"(function() {" | |
| 141 L" var el = document.querySelector('#tip-line');" | |
| 142 L" return el.textContent;" | |
| 143 L"})()" | |
| 144 L")", | |
| 145 &tip_text_content)); | |
| 146 ASSERT_EQ(L"", tip_text_content); | |
| 147 | |
| 148 // Make sure that the notification is visible | |
| 149 bool has_class; | |
| 150 ASSERT_TRUE(tab->ExecuteAndExtractBool(L"", | |
| 151 L"window.domAutomationController.send(" | |
| 152 L"(function() {" | |
| 153 L" var el = document.querySelector('#notification');" | |
| 154 L" return el.classList.contains('show');" | |
| 155 L"})()" | |
| 156 L")", | |
| 157 &has_class)); | |
| 158 ASSERT_TRUE(has_class); | |
| 159 | |
| 160 bool is_home_page; | |
| 161 ASSERT_TRUE(browser->GetBooleanPreference(prefs::kHomePageIsNewTabPage, | |
| 162 &is_home_page)); | |
| 163 ASSERT_TRUE(is_home_page); | |
| 164 } | |
| OLD | NEW |