1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/strings/string_util.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/task_manager/task_manager.h"
#include "chrome/browser/task_manager/task_manager_browsertest_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/omnibox/omnibox_view.h"
#include "chrome/browser/ui/search/instant_ntp.h"
#include "chrome/browser/ui/search/instant_overlay.h"
#include "chrome/browser/ui/search/instant_test_utils.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/search_types.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
#include "googleurl/src/gurl.h"
#include "net/base/network_change_notifier.h"
#include "net/dns/mock_host_resolver.h"
// !!! IMPORTANT !!!
// These tests are run against a mock GWS using the web-page-replay system.
// If you change a test, you MUST re-record the mock GWS session.
// See: src/chrome/test/data/search/tools/instant_extended_manual_tests.py
// for details.
// Instant extended tests that need to be run manually because they need to
// talk to the external network. All tests in this file should be marked as
// "MANUAL_" unless they are disabled.
class InstantExtendedManualTest : public InProcessBrowserTest,
public InstantTestBase {
public:
InstantExtendedManualTest() {
host_resolver_proc_ = new net::RuleBasedHostResolverProc(NULL);
host_resolver_proc_->AllowDirectLookup("*");
scoped_host_resolver_proc_.reset(
new net::ScopedDefaultHostResolverProc(host_resolver_proc_.get()));
}
virtual ~InstantExtendedManualTest() {
scoped_host_resolver_proc_.reset();
host_resolver_proc_ = NULL;
}
virtual void SetUpOnMainThread() OVERRIDE {
const testing::TestInfo* const test_info =
testing::UnitTest::GetInstance()->current_test_info();
ASSERT_TRUE(StartsWithASCII(test_info->name(), "MANUAL_", true) ||
StartsWithASCII(test_info->name(), "DISABLED_", true));
// Make IsOffline() return false so we don't try to use the local overlay.
disable_network_change_notifier_.reset(
new net::NetworkChangeNotifier::DisableForTest());
}
virtual void CleanUpOnMainThread() OVERRIDE {
disable_network_change_notifier_.reset();
}
protected:
virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
chrome::EnableInstantExtendedAPIForTesting();
}
content::WebContents* active_tab() {
return browser()->tab_strip_model()->GetActiveWebContents();
}
bool PressBackspace() {
return ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_BACK,
false, false, false, false);
}
bool PressBackspaceAndWaitForSuggestions() {
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_INSTANT_SET_SUGGESTION,
content::NotificationService::AllSources());
bool result = PressBackspace();
observer.Wait();
return result;
}
bool PressBackspaceAndWaitForOverlayToShow() {
InstantTestModelObserver observer(
instant()->model(), SearchMode::MODE_SEARCH_SUGGESTIONS);
return PressBackspace() && observer.WaitForExpectedOverlayState() ==
SearchMode::MODE_SEARCH_SUGGESTIONS;
}
bool PressEnterAndWaitForNavigationWithTitle(content::WebContents* contents,
const string16& title) {
content::TitleWatcher title_watcher(contents, title);
content::WindowedNotificationObserver nav_observer(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
browser()->window()->GetLocationBar()->AcceptInput();
nav_observer.Wait();
return title_watcher.WaitAndGetTitle() == title;
}
GURL GetActiveTabURL() {
return active_tab()->GetController().GetActiveEntry()->GetURL();
}
bool GetSelectionState(bool* selected) {
return GetBoolFromJS(instant()->GetOverlayContents(),
"google.ac.gs().api.i()", selected);
}
bool IsGooglePage(content::WebContents* contents) {
bool is_google = false;
if (!GetBoolFromJS(contents, "!!window.google", &is_google))
return false;
return is_google;
}
private:
scoped_refptr<net::RuleBasedHostResolverProc> host_resolver_proc_;
scoped_ptr<net::ScopedDefaultHostResolverProc> scoped_host_resolver_proc_;
scoped_ptr<net::NetworkChangeNotifier::DisableForTest>
disable_network_change_notifier_;
};
IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest, MANUAL_ShowsGoogleNTP) {
set_browser(browser());
instant()->SetInstantEnabled(false, true);
instant()->SetInstantEnabled(true, false);
FocusOmniboxAndWaitForInstantNTPSupport();
ui_test_utils::NavigateToURLWithDisposition(
browser(),
GURL(chrome::kChromeUINewTabURL),
NEW_FOREGROUND_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
content::WebContents* active_tab =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_TRUE(IsGooglePage(active_tab));
}
|