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

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

Issue 10815025: Move TitleWatcher from ui_test_utils.h to browser_test_utils.h so it can be reused by content_brows… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 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
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/string_number_conversions.h" 6 #include "base/string_number_conversions.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/app/chrome_command_ids.h" 8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/tab_contents/render_view_context_menu.h" 9 #include "chrome/browser/tab_contents/render_view_context_menu.h"
10 #include "chrome/browser/tab_contents/render_view_context_menu_browsertest_util. h" 10 #include "chrome/browser/tab_contents/render_view_context_menu_browsertest_util. h"
11 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_commands.h" 12 #include "chrome/browser/ui/browser_commands.h"
13 #include "chrome/browser/ui/browser_tabstrip.h" 13 #include "chrome/browser/ui/browser_tabstrip.h"
14 #include "chrome/browser/ui/tab_contents/tab_contents.h" 14 #include "chrome/browser/ui/tab_contents/tab_contents.h"
15 #include "chrome/common/chrome_notification_types.h" 15 #include "chrome/common/chrome_notification_types.h"
16 #include "chrome/test/base/in_process_browser_test.h" 16 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
18 #include "content/public/browser/notification_service.h" 18 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/render_view_host.h" 19 #include "content/public/browser/render_view_host.h"
20 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
21 #include "content/public/test/browser_test_utils.h"
21 #include "net/test/test_server.h" 22 #include "net/test/test_server.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
23 24
24 // GTK requires a X11-level mouse event to open a context menu correctly. 25 // GTK requires a X11-level mouse event to open a context menu correctly.
25 #if defined(TOOLKIT_GTK) 26 #if defined(TOOLKIT_GTK)
26 #define MAYBE_ContextMenuOrigin DISABLED_ContextMenuOrigin 27 #define MAYBE_ContextMenuOrigin DISABLED_ContextMenuOrigin
27 #define MAYBE_HttpsContextMenuOrigin DISABLED_HttpsContextMenuOrigin 28 #define MAYBE_HttpsContextMenuOrigin DISABLED_HttpsContextMenuOrigin
28 #define MAYBE_ContextMenuRedirect DISABLED_ContextMenuRedirect 29 #define MAYBE_ContextMenuRedirect DISABLED_ContextMenuRedirect
29 #define MAYBE_HttpsContextMenuRedirect DISABLED_HttpsContextMenuRedirect 30 #define MAYBE_HttpsContextMenuRedirect DISABLED_HttpsContextMenuRedirect
30 #else 31 #else
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 case EXPECT_ORIGIN_AS_REFERRER: 82 case EXPECT_ORIGIN_AS_REFERRER:
82 referrer = "Referrer is " + url.GetWithEmptyPath().spec(); 83 referrer = "Referrer is " + url.GetWithEmptyPath().spec();
83 break; 84 break;
84 } 85 }
85 return ASCIIToUTF16(referrer); 86 return ASCIIToUTF16(referrer);
86 } 87 }
87 88
88 // Adds all possible titles to the TitleWatcher, so we don't time out 89 // Adds all possible titles to the TitleWatcher, so we don't time out
89 // waiting for the title if the test fails. 90 // waiting for the title if the test fails.
90 void AddAllPossibleTitles(const GURL& url, 91 void AddAllPossibleTitles(const GURL& url,
91 ui_test_utils::TitleWatcher* title_watcher) { 92 content::TitleWatcher* title_watcher) {
92 title_watcher->AlsoWaitForTitle( 93 title_watcher->AlsoWaitForTitle(
93 GetExpectedTitle(url, EXPECT_EMPTY_REFERRER)); 94 GetExpectedTitle(url, EXPECT_EMPTY_REFERRER));
94 title_watcher->AlsoWaitForTitle( 95 title_watcher->AlsoWaitForTitle(
95 GetExpectedTitle(url, EXPECT_FULL_REFERRER)); 96 GetExpectedTitle(url, EXPECT_FULL_REFERRER));
96 title_watcher->AlsoWaitForTitle( 97 title_watcher->AlsoWaitForTitle(
97 GetExpectedTitle(url, EXPECT_ORIGIN_AS_REFERRER)); 98 GetExpectedTitle(url, EXPECT_ORIGIN_AS_REFERRER));
98 } 99 }
99 100
100 // Navigates from a page with a given |referrer_policy| and checks that the 101 // Navigates from a page with a given |referrer_policy| and checks that the
101 // reported referrer matches the expectation. 102 // reported referrer matches the expectation.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 "&redirect=" + (redirect ? "true" : "false") + 134 "&redirect=" + (redirect ? "true" : "false") +
134 "&link=" + 135 "&link=" +
135 (button == WebKit::WebMouseEvent::ButtonNone ? "false" : "true") + 136 (button == WebKit::WebMouseEvent::ButtonNone ? "false" : "true") +
136 "&target=" + (target_blank ? "_blank" : "")); 137 "&target=" + (target_blank ? "_blank" : ""));
137 138
138 ui_test_utils::WindowedTabAddedNotificationObserver tab_added_observer( 139 ui_test_utils::WindowedTabAddedNotificationObserver tab_added_observer(
139 content::NotificationService::AllSources()); 140 content::NotificationService::AllSources());
140 141
141 string16 expected_title = GetExpectedTitle(start_url, expected_referrer); 142 string16 expected_title = GetExpectedTitle(start_url, expected_referrer);
142 content::WebContents* tab = chrome::GetActiveWebContents(browser()); 143 content::WebContents* tab = chrome::GetActiveWebContents(browser());
143 ui_test_utils::TitleWatcher title_watcher(tab, expected_title); 144 content::TitleWatcher title_watcher(tab, expected_title);
144 145
145 // Watch for all possible outcomes to avoid timeouts if something breaks. 146 // Watch for all possible outcomes to avoid timeouts if something breaks.
146 AddAllPossibleTitles(start_url, &title_watcher); 147 AddAllPossibleTitles(start_url, &title_watcher);
147 148
148 ui_test_utils::NavigateToURL(browser(), start_url); 149 ui_test_utils::NavigateToURL(browser(), start_url);
149 150
150 if (button != WebKit::WebMouseEvent::ButtonNone) { 151 if (button != WebKit::WebMouseEvent::ButtonNone) {
151 WebKit::WebMouseEvent mouse_event; 152 WebKit::WebMouseEvent mouse_event;
152 mouse_event.type = WebKit::WebInputEvent::MouseDown; 153 mouse_event.type = WebKit::WebInputEvent::MouseDown;
153 mouse_event.button = button; 154 mouse_event.button = button;
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 GURL start_url = RunReferrerTest("origin", true, false, true, false, 374 GURL start_url = RunReferrerTest("origin", true, false, true, false,
374 WebKit::WebMouseEvent::ButtonLeft, 375 WebKit::WebMouseEvent::ButtonLeft,
375 EXPECT_ORIGIN_AS_REFERRER); 376 EXPECT_ORIGIN_AS_REFERRER);
376 377
377 // Navigate to C. 378 // Navigate to C.
378 ui_test_utils::NavigateToURL(browser(), test_server_->GetURL("")); 379 ui_test_utils::NavigateToURL(browser(), test_server_->GetURL(""));
379 380
380 string16 expected_title = 381 string16 expected_title =
381 GetExpectedTitle(start_url, EXPECT_ORIGIN_AS_REFERRER); 382 GetExpectedTitle(start_url, EXPECT_ORIGIN_AS_REFERRER);
382 content::WebContents* tab = chrome::GetActiveWebContents(browser()); 383 content::WebContents* tab = chrome::GetActiveWebContents(browser());
383 scoped_ptr<ui_test_utils::TitleWatcher> title_watcher( 384 scoped_ptr<content::TitleWatcher> title_watcher(
384 new ui_test_utils::TitleWatcher(tab, expected_title)); 385 new content::TitleWatcher(tab, expected_title));
385 386
386 // Watch for all possible outcomes to avoid timeouts if something breaks. 387 // Watch for all possible outcomes to avoid timeouts if something breaks.
387 AddAllPossibleTitles(start_url, title_watcher.get()); 388 AddAllPossibleTitles(start_url, title_watcher.get());
388 389
389 // Go back to B. 390 // Go back to B.
390 chrome::GoBack(browser(), CURRENT_TAB); 391 chrome::GoBack(browser(), CURRENT_TAB);
391 EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle()); 392 EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle());
392 393
393 title_watcher.reset(new ui_test_utils::TitleWatcher(tab, expected_title)); 394 title_watcher.reset(new content::TitleWatcher(tab, expected_title));
394 AddAllPossibleTitles(start_url, title_watcher.get()); 395 AddAllPossibleTitles(start_url, title_watcher.get());
395 396
396 // Reload to B. 397 // Reload to B.
397 chrome::Reload(browser(), CURRENT_TAB); 398 chrome::Reload(browser(), CURRENT_TAB);
398 EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle()); 399 EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle());
399 400
400 title_watcher.reset(new ui_test_utils::TitleWatcher(tab, expected_title)); 401 title_watcher.reset(new content::TitleWatcher(tab, expected_title));
401 AddAllPossibleTitles(start_url, title_watcher.get()); 402 AddAllPossibleTitles(start_url, title_watcher.get());
402 403
403 // Shift-reload to B. 404 // Shift-reload to B.
404 chrome::ReloadIgnoringCache(browser(), CURRENT_TAB); 405 chrome::ReloadIgnoringCache(browser(), CURRENT_TAB);
405 EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle()); 406 EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle());
406 } 407 }
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_browsertest.cc ('k') | chrome/browser/ssl/ssl_browser_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698