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

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

Issue 18093: Changes to insure that when in app-mode, links open in the default browser. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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/browser.h » ('j') | chrome/browser/browser.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Tests browsing in app-mode. Specifically, insures that navigation to
6 // new windows launch in the default protocol handler and that navigations
7 // within the same frame do not. Outside of app-mode these tests are covered
8 // by normal navigation and the fork test.
9
10 #include "base/string_util.h"
11 #include "base/file_util.h"
12 #include "chrome/common/l10n_util.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/test/automation/browser_proxy.h"
15 #include "chrome/test/automation/tab_proxy.h"
16 #include "chrome/test/automation/window_proxy.h"
17 #include "chrome/test/ui/ui_test.h"
18 #include "net/base/net_util.h"
19 #include "net/url_request/url_request_unittest.h"
20
21 #include "chromium_strings.h"
22 #include "generated_resources.h"
23
24 namespace {
25
26 const wchar_t kDocRoot[] = L"chrome/test/data";
27 const wchar_t kTestFileName[] = L"appmodenavigation_test.html";
28
29 class AppModeNavigationTest : public UITest {
30 protected:
31 AppModeNavigationTest() : UITest() {
32 show_window_ = true;
33
34 // Launch chrome in app mode.
35 std::wstring test_file = test_data_directory_;
36 file_util::AppendToPath(&test_file, kTestFileName);
37 std::wstring url = ASCIIToWide(net::FilePathToFileURL(test_file).spec());
38 launch_arguments_.AppendSwitchWithValue(switches::kApp, url);
39 }
40
41 // Helper function for evaluation.
42 HWND GetMainBrowserWindow() {
43 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
44 scoped_ptr<WindowProxy> window(browser->GetWindow());
45
46 HWND window_handle;
47 EXPECT_TRUE(window->GetHWND(&window_handle));
48 return window_handle;
49 }
50
51 // Get the window title from the main window.
52 std::wstring GetMainBrowserWindowTitle() {
53 HWND window_handle = GetMainBrowserWindow();
54 std::wstring result;
55 int length = ::GetWindowTextLength(window_handle) + 1;
56 ::GetWindowText(window_handle, WriteInto(&result, length), length);
57 return result;
58 }
59
60 // Given a page title, returns the expected window caption string.
61 std::wstring WindowCaptionFromPageTitle(const std::wstring& page_title) {
62 if (page_title.empty())
63 return l10n_util::GetString(IDS_PRODUCT_NAME);
64 return l10n_util::GetStringF(IDS_BROWSER_WINDOW_TITLE_FORMAT, page_title);
65 }
66
67 // Selects the anchor tag by index and navigates to it. This is necssary
68 // since the automation API's navigate the window by simulating address bar
69 // entries.
70 void NavigateToIndex(int index) {
71 scoped_ptr<WindowProxy> window(automation()->GetActiveWindow());
72 ASSERT_TRUE(window->Activate());
73 Sleep(action_timeout_ms());
74 // We are in app mode, hence tab moves from focus to the next UI element
75 // in the view.
76 for (; index > 0; --index) {
77 window->SimulateOSKeyPress(L'\t', 0); // 0 signifies no modifier.
78 }
79 Sleep(action_timeout_ms());
80 window->SimulateOSKeyPress(L'\r', 0);
81 Sleep(action_timeout_ms());
82 }
83
84 // Validates that the foreground window is the external protocol handler
85 // validation window, and if so dismisses it by clicking on the default
86 // input.
87 bool DismissExternalLauncherPopup() {
88 // The currently active window should be the protocol handler if this is
89 // and external link.
90 scoped_ptr<WindowProxy> window(automation()->GetActiveWindow());
91 HWND hwnd;
92 if (!window->GetHWND(&hwnd))
93 return false;
94
95 int size = ::GetWindowTextLengthW(hwnd);
96 scoped_ptr<wchar_t> buffer(new wchar_t[size+1]);
97 if (NULL == buffer.get())
98 return false;
99 ::GetWindowText(hwnd, buffer.get(), size+1);
100 if (0 != wcscmp(L"External Protocol Request", buffer.get()))
101 return false;
102
103 // The default UI element is the |Cancel| button.
104 window->SimulateOSKeyPress(L'\r', 0);
105 Sleep(action_timeout_ms());
106
107 return true;
108 }
109 };
110
111
112 // Follow an normal anchor tag with target=blank (external tab).
113 TEST_F(AppModeNavigationTest, NavigateToNewTab) {
114 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
115 scoped_ptr<TabProxy> tab(browser->GetActiveTab());
116
117 int orig_tab_count = -1;
118 ASSERT_TRUE(browser->GetTabCount(&orig_tab_count));
119 int orig_process_count = GetBrowserProcessCount();
120 ASSERT_TRUE(orig_process_count >= 1);
121
122 NavigateToIndex(1); // First link test.
123
124 ASSERT_TRUE(DismissExternalLauncherPopup());
125
126 // Insure all the other processes have terminated.
127 ASSERT_EQ(orig_process_count, GetBrowserProcessCount());
128
129 // In app-mode there is a single tab.
130 int new_tab_count = -1;
131 ASSERT_TRUE(browser->GetTabCount(&new_tab_count));
132 ASSERT_EQ(orig_tab_count, new_tab_count);
133
134 // We must not have navigated.
135 EXPECT_EQ(WindowCaptionFromPageTitle(kTestFileName),
136 GetMainBrowserWindowTitle());
137 EXPECT_EQ(kTestFileName, GetActiveTabTitle());
138 }
139
140 // Open a new tab with a redirect as Gmail does.
141 TEST_F(AppModeNavigationTest, NavigateByForkToNewTabTest) {
142 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
143 scoped_ptr<TabProxy> tab(browser->GetActiveTab());
144
145 int orig_tab_count = -1;
146 ASSERT_TRUE(browser->GetTabCount(&orig_tab_count));
147 int orig_process_count = GetBrowserProcessCount();
148 ASSERT_TRUE(orig_process_count >= 1);
149
150 NavigateToIndex(2); // Second link test.
151
152 ASSERT_TRUE(DismissExternalLauncherPopup());
153
154 // Insure all the other processes have terminated.
155 ASSERT_EQ(orig_process_count, GetBrowserProcessCount());
156
157 // In app-mode there is a single tab.
158 int new_tab_count = -1;
159 ASSERT_TRUE(browser->GetTabCount(&new_tab_count));
160 ASSERT_EQ(orig_tab_count, new_tab_count);
161
162 // We must not have navigated.
163 EXPECT_EQ(WindowCaptionFromPageTitle(kTestFileName),
164 GetMainBrowserWindowTitle());
165 EXPECT_EQ(kTestFileName, GetActiveTabTitle());
166 }
167
168 // Normal navigation
169 TEST_F(AppModeNavigationTest, NavigateToAboutBlankByLink) {
170 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
171 scoped_ptr<TabProxy> tab(browser->GetActiveTab());
172
173 int orig_tab_count = -1;
174 ASSERT_TRUE(browser->GetTabCount(&orig_tab_count));
175 int orig_process_count = GetBrowserProcessCount();
176 ASSERT_TRUE(orig_process_count >= 1);
177
178 NavigateToIndex(3); // Third link test.
179
180 // Insure all the other processes have terminated.
181 ASSERT_EQ(orig_process_count, GetBrowserProcessCount());
182
183 // In app-mode there is a single tab.
184 int new_tab_count = -1;
185 ASSERT_TRUE(browser->GetTabCount(&new_tab_count));
186 ASSERT_EQ(orig_tab_count, new_tab_count);
187
188 // We must not have navigated.
189 EXPECT_EQ(WindowCaptionFromPageTitle(L"about:blank"),
190 GetMainBrowserWindowTitle());
191 EXPECT_EQ(L"", GetActiveTabTitle());
192 }
193
194 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/browser.h » ('j') | chrome/browser/browser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698