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

Side by Side Diff: third_party/WebKit/Source/web/tests/ChromeClientImplTest.cpp

Issue 2905283003: Remove a bunch of dead code around WindowFeatures (Closed)
Patch Set: Add missing #include Created 3 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 ~TestWebViewClient() override {} 57 ~TestWebViewClient() override {}
58 58
59 void Show(WebNavigationPolicy policy) override { *target_ = policy; } 59 void Show(WebNavigationPolicy policy) override { *target_ = policy; }
60 60
61 private: 61 private:
62 WebNavigationPolicy* target_; 62 WebNavigationPolicy* target_;
63 }; 63 };
64 64
65 } // anonymous namespace 65 } // anonymous namespace
66 66
67 class GetNavigationPolicyTest : public testing::Test {
Nate Chapin 2017/05/31 16:55:13 Moved to a new file (EffectiveNavigationPolicyTest
68 public:
69 GetNavigationPolicyTest()
70 : result_(kWebNavigationPolicyIgnore), web_view_client_(&result_) {}
71
72 protected:
73 void SetUp() override {
74 web_view_ = static_cast<WebViewBase*>(
75 WebViewBase::Create(&web_view_client_, kWebPageVisibilityStateVisible));
76 web_view_->SetMainFrame(WebLocalFrame::Create(
77 WebTreeScopeType::kDocument, &web_frame_client_, nullptr, nullptr));
78 chrome_client_impl_ =
79 ToChromeClientImpl(&web_view_->GetPage()->GetChromeClient());
80 result_ = kWebNavigationPolicyIgnore;
81 }
82
83 void TearDown() override { web_view_->Close(); }
84
85 WebNavigationPolicy GetNavigationPolicyWithMouseEvent(
86 int modifiers,
87 WebMouseEvent::Button button,
88 bool as_popup) {
89 WebMouseEvent event(WebInputEvent::kMouseUp, modifiers,
90 WebInputEvent::kTimeStampForTesting);
91 event.button = button;
92 web_view_->SetCurrentInputEventForTest(&event);
93 chrome_client_impl_->SetToolbarsVisible(!as_popup);
94 chrome_client_impl_->Show(kNavigationPolicyIgnore);
95 web_view_->SetCurrentInputEventForTest(0);
96 return result_;
97 }
98
99 bool IsNavigationPolicyPopup() {
100 chrome_client_impl_->Show(kNavigationPolicyIgnore);
101 return result_ == kWebNavigationPolicyNewPopup;
102 }
103
104 protected:
105 WebNavigationPolicy result_;
106 TestWebViewClient web_view_client_;
107 WebViewBase* web_view_;
108 FrameTestHelpers::TestWebFrameClient web_frame_client_;
109 Persistent<ChromeClientImpl> chrome_client_impl_;
110 };
111
112 TEST_F(GetNavigationPolicyTest, LeftClick) {
113 int modifiers = 0;
114 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft;
115 bool as_popup = false;
116 EXPECT_EQ(kWebNavigationPolicyNewForegroundTab,
117 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup));
118 }
119
120 TEST_F(GetNavigationPolicyTest, LeftClickPopup) {
121 int modifiers = 0;
122 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft;
123 bool as_popup = true;
124 EXPECT_EQ(kWebNavigationPolicyNewPopup,
125 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup));
126 }
127
128 TEST_F(GetNavigationPolicyTest, ShiftLeftClick) {
129 int modifiers = WebInputEvent::kShiftKey;
130 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft;
131 bool as_popup = false;
132 EXPECT_EQ(kWebNavigationPolicyNewWindow,
133 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup));
134 }
135
136 TEST_F(GetNavigationPolicyTest, ShiftLeftClickPopup) {
137 int modifiers = WebInputEvent::kShiftKey;
138 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft;
139 bool as_popup = true;
140 EXPECT_EQ(kWebNavigationPolicyNewPopup,
141 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup));
142 }
143
144 TEST_F(GetNavigationPolicyTest, ControlOrMetaLeftClick) {
145 #if OS(MACOSX)
146 int modifiers = WebInputEvent::kMetaKey;
147 #else
148 int modifiers = WebInputEvent::kControlKey;
149 #endif
150 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft;
151 bool as_popup = false;
152 EXPECT_EQ(kWebNavigationPolicyNewBackgroundTab,
153 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup));
154 }
155
156 TEST_F(GetNavigationPolicyTest, ControlOrMetaLeftClickPopup) {
157 #if OS(MACOSX)
158 int modifiers = WebInputEvent::kMetaKey;
159 #else
160 int modifiers = WebInputEvent::kControlKey;
161 #endif
162 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft;
163 bool as_popup = true;
164 EXPECT_EQ(kWebNavigationPolicyNewBackgroundTab,
165 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup));
166 }
167
168 TEST_F(GetNavigationPolicyTest, ControlOrMetaAndShiftLeftClick) {
169 #if OS(MACOSX)
170 int modifiers = WebInputEvent::kMetaKey;
171 #else
172 int modifiers = WebInputEvent::kControlKey;
173 #endif
174 modifiers |= WebInputEvent::kShiftKey;
175 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft;
176 bool as_popup = false;
177 EXPECT_EQ(kWebNavigationPolicyNewForegroundTab,
178 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup));
179 }
180
181 TEST_F(GetNavigationPolicyTest, ControlOrMetaAndShiftLeftClickPopup) {
182 #if OS(MACOSX)
183 int modifiers = WebInputEvent::kMetaKey;
184 #else
185 int modifiers = WebInputEvent::kControlKey;
186 #endif
187 modifiers |= WebInputEvent::kShiftKey;
188 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft;
189 bool as_popup = true;
190 EXPECT_EQ(kWebNavigationPolicyNewForegroundTab,
191 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup));
192 }
193
194 TEST_F(GetNavigationPolicyTest, MiddleClick) {
195 int modifiers = 0;
196 bool as_popup = false;
197 WebMouseEvent::Button button = WebMouseEvent::Button::kMiddle;
198 EXPECT_EQ(kWebNavigationPolicyNewBackgroundTab,
199 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup));
200 }
201
202 TEST_F(GetNavigationPolicyTest, MiddleClickPopup) {
203 int modifiers = 0;
204 bool as_popup = true;
205 WebMouseEvent::Button button = WebMouseEvent::Button::kMiddle;
206 EXPECT_EQ(kWebNavigationPolicyNewBackgroundTab,
207 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup));
208 }
209
210 TEST_F(GetNavigationPolicyTest, NoToolbarsForcesPopup) {
211 chrome_client_impl_->SetToolbarsVisible(false);
212 EXPECT_TRUE(IsNavigationPolicyPopup());
213 chrome_client_impl_->SetToolbarsVisible(true);
214 EXPECT_FALSE(IsNavigationPolicyPopup());
215 }
216
217 TEST_F(GetNavigationPolicyTest, NoStatusbarIsNotPopup) {
Nate Chapin 2017/05/31 16:55:13 I dropped these last 3 tests, because the signatur
218 chrome_client_impl_->SetStatusbarVisible(false);
219 EXPECT_FALSE(IsNavigationPolicyPopup());
220 chrome_client_impl_->SetStatusbarVisible(true);
221 EXPECT_FALSE(IsNavigationPolicyPopup());
222 }
223
224 TEST_F(GetNavigationPolicyTest, NoMenubarIsNotPopup) {
225 chrome_client_impl_->SetMenubarVisible(false);
226 EXPECT_FALSE(IsNavigationPolicyPopup());
227 chrome_client_impl_->SetMenubarVisible(true);
228 EXPECT_FALSE(IsNavigationPolicyPopup());
229 }
230
231 TEST_F(GetNavigationPolicyTest, NotResizableIsNotPopup) {
232 chrome_client_impl_->SetResizable(false);
233 EXPECT_FALSE(IsNavigationPolicyPopup());
234 chrome_client_impl_->SetResizable(true);
235 EXPECT_FALSE(IsNavigationPolicyPopup());
236 }
237
238 class ViewCreatingClient : public FrameTestHelpers::TestWebViewClient { 67 class ViewCreatingClient : public FrameTestHelpers::TestWebViewClient {
239 public: 68 public:
240 WebView* CreateView(WebLocalFrame* opener, 69 WebView* CreateView(WebLocalFrame* opener,
241 const WebURLRequest&, 70 const WebURLRequest&,
242 const WebWindowFeatures&, 71 const WebWindowFeatures&,
243 const WebString& name, 72 const WebString& name,
244 WebNavigationPolicy, 73 WebNavigationPolicy,
245 bool) override { 74 bool) override {
246 return web_view_helper_.InitializeWithOpener(opener, true); 75 return web_view_helper_.InitializeWithOpener(opener, true);
247 } 76 }
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 Settings* settings = GetSettings(); 256 Settings* settings = GetSettings();
428 settings->SetPagePopupsSuppressed(true); 257 settings->SetPagePopupsSuppressed(true);
429 258
430 EXPECT_FALSE(CanOpenPopupMenu()); 259 EXPECT_FALSE(CanOpenPopupMenu());
431 260
432 settings->SetPagePopupsSuppressed(false); 261 settings->SetPagePopupsSuppressed(false);
433 EXPECT_TRUE(CanOpenPopupMenu()); 262 EXPECT_TRUE(CanOpenPopupMenu());
434 } 263 }
435 264
436 } // namespace blink 265 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698