Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(627)

Side by Side Diff: chrome/browser/browser_focus_uitest.cc

Issue 9597005: Revert 124890 - Convert uses of int ms to TimeDelta in chrome/browser and net. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/debugger/devtools_sanity_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 138
139 // Wait the focus change in message loop. 139 // Wait the focus change in message loop.
140 void CheckFocus(Browser* browser, ViewID id, const base::Time& timeout) { 140 void CheckFocus(Browser* browser, ViewID id, const base::Time& timeout) {
141 if (ui_test_utils::IsViewFocused(browser, id) || 141 if (ui_test_utils::IsViewFocused(browser, id) ||
142 base::Time::Now() > timeout) { 142 base::Time::Now() > timeout) {
143 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 143 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
144 } else { 144 } else {
145 MessageLoop::current()->PostDelayedTask( 145 MessageLoop::current()->PostDelayedTask(
146 FROM_HERE, 146 FROM_HERE,
147 base::Bind(&CheckFocus, browser, id, timeout), 147 base::Bind(&CheckFocus, browser, id, timeout),
148 base::TimeDelta::FromMilliseconds(10)); 148 10);
149 } 149 }
150 }; 150 };
151 151
152 class BrowserFocusTest : public InProcessBrowserTest { 152 class BrowserFocusTest : public InProcessBrowserTest {
153 public: 153 public:
154 BrowserFocusTest() : 154 BrowserFocusTest() :
155 #if defined(USE_AURA) 155 #if defined(USE_AURA)
156 location_bar_focus_view_id_(VIEW_ID_OMNIBOX) 156 location_bar_focus_view_id_(VIEW_ID_OMNIBOX)
157 #else 157 #else
158 location_bar_focus_view_id_(VIEW_ID_LOCATION_BAR) 158 location_bar_focus_view_id_(VIEW_ID_LOCATION_BAR)
(...skipping 10 matching lines...) Expand all
169 void ClickOnView(ViewID vid) { 169 void ClickOnView(ViewID vid) {
170 ui_test_utils::ClickOnView(browser(), vid); 170 ui_test_utils::ClickOnView(browser(), vid);
171 } 171 }
172 172
173 bool WaitForFocusChange(ViewID vid) { 173 bool WaitForFocusChange(ViewID vid) {
174 const base::Time timeout = base::Time::Now() + 174 const base::Time timeout = base::Time::Now() +
175 base::TimeDelta::FromMilliseconds(kFocusChangeTimeoutMs); 175 base::TimeDelta::FromMilliseconds(kFocusChangeTimeoutMs);
176 MessageLoop::current()->PostDelayedTask( 176 MessageLoop::current()->PostDelayedTask(
177 FROM_HERE, 177 FROM_HERE,
178 base::Bind(&CheckFocus, browser(), vid, timeout), 178 base::Bind(&CheckFocus, browser(), vid, timeout),
179 base::TimeDelta::FromMilliseconds(100)); 179 100);
180 ui_test_utils::RunMessageLoop(); 180 ui_test_utils::RunMessageLoop();
181 return IsViewFocused(vid); 181 return IsViewFocused(vid);
182 } 182 }
183 183
184 ViewID location_bar_focus_view_id_; 184 ViewID location_bar_focus_view_id_;
185 }; 185 };
186 186
187 class TestInterstitialPage : public content::InterstitialPageDelegate { 187 class TestInterstitialPage : public content::InterstitialPageDelegate {
188 public: 188 public:
189 TestInterstitialPage(WebContents* tab, bool new_navigation, const GURL& url) { 189 TestInterstitialPage(WebContents* tab, bool new_navigation, const GURL& url) {
(...skipping 28 matching lines...) Expand all
218 private: 218 private:
219 std::string html_contents_; 219 std::string html_contents_;
220 InterstitialPage* interstitial_page_; // Owns us. 220 InterstitialPage* interstitial_page_; // Owns us.
221 }; 221 };
222 222
223 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) { 223 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) {
224 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 224 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
225 #if defined(OS_POSIX) 225 #if defined(OS_POSIX)
226 // It seems we have to wait a little bit for the widgets to spin up before 226 // It seems we have to wait a little bit for the widgets to spin up before
227 // we can start clicking on them. 227 // we can start clicking on them.
228 MessageLoop::current()->PostDelayedTask( 228 MessageLoop::current()->PostDelayedTask(FROM_HERE,
229 FROM_HERE, 229 MessageLoop::QuitClosure(),
230 MessageLoop::QuitClosure(), 230 kActionDelayMs);
231 base::TimeDelta::FromMilliseconds(kActionDelayMs));
232 ui_test_utils::RunMessageLoop(); 231 ui_test_utils::RunMessageLoop();
233 #endif // defined(OS_POSIX) 232 #endif // defined(OS_POSIX)
234 233
235 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); 234 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_));
236 235
237 ClickOnView(VIEW_ID_TAB_CONTAINER); 236 ClickOnView(VIEW_ID_TAB_CONTAINER);
238 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 237 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
239 238
240 ClickOnView(VIEW_ID_LOCATION_BAR); 239 ClickOnView(VIEW_ID_LOCATION_BAR);
241 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); 240 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_));
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 // Focus should be on the page. 620 // Focus should be on the page.
622 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 621 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
623 622
624 // Let's show an interstitial. 623 // Let's show an interstitial.
625 TestInterstitialPage* interstitial_page = 624 TestInterstitialPage* interstitial_page =
626 new TestInterstitialPage(browser()->GetSelectedWebContents(), 625 new TestInterstitialPage(browser()->GetSelectedWebContents(),
627 true, GURL("http://interstitial.com")); 626 true, GURL("http://interstitial.com"));
628 // Give some time for the interstitial to show. 627 // Give some time for the interstitial to show.
629 MessageLoop::current()->PostDelayedTask(FROM_HERE, 628 MessageLoop::current()->PostDelayedTask(FROM_HERE,
630 MessageLoop::QuitClosure(), 629 MessageLoop::QuitClosure(),
631 base::TimeDelta::FromSeconds(1)); 630 1000);
632 ui_test_utils::RunMessageLoop(); 631 ui_test_utils::RunMessageLoop();
633 632
634 browser()->FocusLocationBar(); 633 browser()->FocusLocationBar();
635 634
636 const char* kExpElementIDs[] = { 635 const char* kExpElementIDs[] = {
637 "", // Initially no element in the page should be focused 636 "", // Initially no element in the page should be focused
638 // (the location bar is focused). 637 // (the location bar is focused).
639 "textEdit", "searchButton", "luckyButton", "googleLink", "gmailLink", 638 "textEdit", "searchButton", "luckyButton", "googleLink", "gmailLink",
640 "gmapLink" 639 "gmapLink"
641 }; 640 };
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 EXPECT_TRUE(browser()->GetSelectedWebContents()->GetRenderViewHost()->view()-> 745 EXPECT_TRUE(browser()->GetSelectedWebContents()->GetRenderViewHost()->view()->
747 HasFocus()); 746 HasFocus());
748 747
749 // Let's show an interstitial. 748 // Let's show an interstitial.
750 TestInterstitialPage* interstitial_page = 749 TestInterstitialPage* interstitial_page =
751 new TestInterstitialPage(browser()->GetSelectedWebContents(), 750 new TestInterstitialPage(browser()->GetSelectedWebContents(),
752 true, GURL("http://interstitial.com")); 751 true, GURL("http://interstitial.com"));
753 // Give some time for the interstitial to show. 752 // Give some time for the interstitial to show.
754 MessageLoop::current()->PostDelayedTask(FROM_HERE, 753 MessageLoop::current()->PostDelayedTask(FROM_HERE,
755 MessageLoop::QuitClosure(), 754 MessageLoop::QuitClosure(),
756 base::TimeDelta::FromSeconds(1)); 755 1000);
757 ui_test_utils::RunMessageLoop(); 756 ui_test_utils::RunMessageLoop();
758 757
759 // The interstitial should have focus now. 758 // The interstitial should have focus now.
760 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 759 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
761 EXPECT_TRUE(interstitial_page->HasFocus()); 760 EXPECT_TRUE(interstitial_page->HasFocus());
762 761
763 // Hide the interstitial. 762 // Hide the interstitial.
764 interstitial_page->DontProceed(); 763 interstitial_page->DontProceed();
765 764
766 // Focus should be back on the original page. 765 // Focus should be back on the original page.
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 browser()->Reload(CURRENT_TAB); 919 browser()->Reload(CURRENT_TAB);
921 observer.Wait(); 920 observer.Wait();
922 } 921 }
923 922
924 // Focus should now be on the tab contents. 923 // Focus should now be on the tab contents.
925 browser()->ShowDownloadsTab(); 924 browser()->ShowDownloadsTab();
926 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 925 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
927 } 926 }
928 927
929 } // namespace 928 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/debugger/devtools_sanity_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698