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
|
// 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/chrome_notification_types.h"
#include "chrome/browser/search/instant_service.h"
#include "chrome/browser/search/instant_service_factory.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_test_utils.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/omnibox_focus_state.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 "net/base/network_change_notifier.h"
#include "net/dns/mock_host_resolver.h"
#include "url/gurl.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 NTP.
disable_network_change_notifier_.reset(
new net::NetworkChangeNotifier::DisableForTest());
}
virtual void TearDownOnMainThread() OVERRIDE {
disable_network_change_notifier_.reset();
}
protected:
virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
chrome::EnableQueryExtractionForTesting();
}
content::WebContents* active_tab() {
return browser()->tab_strip_model()->GetActiveWebContents();
}
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_SearchesFromFakebox) {
set_browser(browser());
FocusOmnibox();
// Open a new tab page.
content::WindowedNotificationObserver observer(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
ui_test_utils::NavigateToURLWithDisposition(
browser(),
GURL(chrome::kChromeUINewTabURL),
CURRENT_TAB,
ui_test_utils::BROWSER_TEST_NONE);
observer.Wait();
content::WebContents* active_tab =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(IsGooglePage(active_tab));
// Click in the fakebox and expect invisible focus.
ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
bool fakebox_is_present = false;
content::WindowedNotificationObserver focus_observer(
chrome::NOTIFICATION_OMNIBOX_FOCUS_CHANGED,
content::NotificationService::AllSources());
ASSERT_TRUE(GetBoolFromJS(active_tab, "!!document.querySelector('#fkbx')",
&fakebox_is_present));
ASSERT_TRUE(fakebox_is_present);
ASSERT_TRUE(content::ExecuteScript(
active_tab, "document.querySelector('#fkbx').click()"));
focus_observer.Wait();
EXPECT_EQ(OMNIBOX_FOCUS_INVISIBLE, omnibox()->model()->focus_state());
// Type "test".
const ui::KeyboardCode query[] = {
ui::VKEY_T, ui::VKEY_E, ui::VKEY_S, ui::VKEY_T,
ui::VKEY_UNKNOWN
};
for (size_t i = 0; query[i] != ui::VKEY_UNKNOWN; i++) {
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), query[i],
false, false, false, false));
}
// The omnibox should say "test" and have visible focus.
EXPECT_EQ("test", GetOmniboxText());
EXPECT_EQ(OMNIBOX_FOCUS_VISIBLE, omnibox()->model()->focus_state());
// Pressing enter should search for [test].
const base::string16& search_title =
base::ASCIIToUTF16("test - Google Search");
content::TitleWatcher title_watcher(active_tab, search_title);
PressEnterAndWaitForNavigation();
EXPECT_EQ(search_title, title_watcher.WaitAndGetTitle());
}
|