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

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

Issue 2885033007: Disable color/date chooser in VR mode via WebPreferences (Closed)
Patch Set: date time chooser Created 3 years, 7 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 11 matching lines...) Expand all
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "core/exported/WebViewBase.h" 31 #include "core/exported/WebViewBase.h"
32 #include "core/html/forms/ColorChooserClient.h"
33 #include "core/html/forms/DateTimeChooser.h"
34 #include "core/html/forms/DateTimeChooserClient.h"
32 #include "core/loader/FrameLoadRequest.h" 35 #include "core/loader/FrameLoadRequest.h"
33 #include "core/page/Page.h" 36 #include "core/page/Page.h"
34 #include "core/page/ScopedPageSuspender.h" 37 #include "core/page/ScopedPageSuspender.h"
35 #include "public/platform/WebInputEvent.h" 38 #include "public/platform/WebInputEvent.h"
36 #include "public/web/WebFrameClient.h" 39 #include "public/web/WebFrameClient.h"
37 #include "public/web/WebLocalFrame.h" 40 #include "public/web/WebLocalFrame.h"
38 #include "public/web/WebView.h" 41 #include "public/web/WebView.h"
39 #include "public/web/WebViewClient.h" 42 #include "public/web/WebViewClient.h"
40 #include "testing/gtest/include/gtest/gtest.h" 43 #include "testing/gtest/include/gtest/gtest.h"
41 #include "web/ChromeClientImpl.h" 44 #include "web/ChromeClientImpl.h"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 TEST_F(CreateWindowTest, CreateWindowFromSuspendedPage) { 272 TEST_F(CreateWindowTest, CreateWindowFromSuspendedPage) {
270 ScopedPageSuspender suspender; 273 ScopedPageSuspender suspender;
271 LocalFrame* frame = ToWebLocalFrameImpl(main_frame_)->GetFrame(); 274 LocalFrame* frame = ToWebLocalFrameImpl(main_frame_)->GetFrame();
272 FrameLoadRequest request(frame->GetDocument()); 275 FrameLoadRequest request(frame->GetDocument());
273 WindowFeatures features; 276 WindowFeatures features;
274 EXPECT_EQ(nullptr, 277 EXPECT_EQ(nullptr,
275 chrome_client_impl_->CreateWindow( 278 chrome_client_impl_->CreateWindow(
276 frame, request, features, kNavigationPolicyNewForegroundTab)); 279 frame, request, features, kNavigationPolicyNewForegroundTab));
277 } 280 }
278 281
282 class FakeColorChooserClient
283 : public GarbageCollectedFinalized<FakeColorChooserClient>,
284 public ColorChooserClient {
285 public:
286 FakeColorChooserClient(Element* owner_element)
287 : owner_element_(owner_element) {}
288 ~FakeColorChooserClient() override {}
289
290 DEFINE_INLINE_VIRTUAL_TRACE() {
291 visitor->Trace(owner_element_);
292 ColorChooserClient::Trace(visitor);
293 }
294
295 USING_GARBAGE_COLLECTED_MIXIN(FakeColorChooserClient)
296
297 // ColorChooserClient
298 void DidChooseColor(const Color& color) override {}
299 void DidEndChooser() override {}
300 Element& OwnerElement() const override { return *owner_element_; }
301 IntRect ElementRectRelativeToViewport() const override { return IntRect(); }
302 Color CurrentColor() override { return Color(); }
303 bool ShouldShowSuggestions() const override { return false; }
304 Vector<ColorSuggestion> Suggestions() const override {
305 return Vector<ColorSuggestion>();
306 }
307
308 private:
309 Member<Element> owner_element_;
310 };
311
312 class FakeDateTimeChooserClient
313 : public GarbageCollectedFinalized<FakeDateTimeChooserClient>,
314 public DateTimeChooserClient {
315 public:
316 FakeDateTimeChooserClient(Element* owner_element)
317 : owner_element_(owner_element) {}
318 ~FakeDateTimeChooserClient() override {}
319
320 DEFINE_INLINE_VIRTUAL_TRACE() {
321 visitor->Trace(owner_element_);
322 DateTimeChooserClient::Trace(visitor);
323 }
324
325 USING_GARBAGE_COLLECTED_MIXIN(FakeDateTimeChooserClient)
326
327 // DateTimeChooserClient
328 Element& OwnerElement() const override { return *owner_element_; }
329 void DidChooseValue(const String&) override {}
330 void DidChooseValue(double) override {}
331 void DidEndChooser() override {}
332
333 private:
334 Member<Element> owner_element_;
335 };
336
337 class PagePopupSuppressionTest : public testing::Test {
338 public:
339 PagePopupSuppressionTest() {}
340
341 bool CanOpenColorChooser() {
342 LocalFrame* frame = ToWebLocalFrameImpl(main_frame_)->GetFrame();
343 Color color;
344 return !!chrome_client_impl_->OpenColorChooser(frame, color_chooser_client_,
345 color);
346 }
347
348 bool CanOpenDateTimeChooser() {
349 DateTimeChooserParameters params;
350 return !!chrome_client_impl_->OpenDateTimeChooser(date_time_chooser_client_,
351 params);
352 }
353
354 Settings* GetSettings() {
355 LocalFrame* frame = ToWebLocalFrameImpl(main_frame_)->GetFrame();
356 return frame->GetDocument()->GetSettings();
357 }
358
359 protected:
360 void SetUp() override {
361 web_view_ = static_cast<WebViewBase*>(
362 WebViewBase::Create(&web_view_client_, kWebPageVisibilityStateVisible));
363 main_frame_ = WebLocalFrame::Create(WebTreeScopeType::kDocument,
364 &web_frame_client_, nullptr, nullptr);
365 web_view_->SetMainFrame(main_frame_);
366 chrome_client_impl_ =
367 ToChromeClientImpl(&web_view_->GetPage()->GetChromeClient());
368 LocalFrame* frame = ToWebLocalFrameImpl(main_frame_)->GetFrame();
369 color_chooser_client_ =
370 new FakeColorChooserClient(frame->GetDocument()->documentElement());
371 date_time_chooser_client_ =
372 new FakeDateTimeChooserClient(frame->GetDocument()->documentElement());
373 }
374
375 void TearDown() override { web_view_->Close(); }
376
377 protected:
378 FrameTestHelpers::TestWebViewClient web_view_client_;
379 WebViewBase* web_view_ = nullptr;
380 WebLocalFrame* main_frame_ = nullptr;
381 FrameTestHelpers::TestWebFrameClient web_frame_client_;
382 Persistent<ChromeClientImpl> chrome_client_impl_;
383 Persistent<FakeColorChooserClient> color_chooser_client_;
384 Persistent<FakeDateTimeChooserClient> date_time_chooser_client_;
385 };
386
387 TEST_F(PagePopupSuppressionTest, SuppressColorChooser) {
388 // By default, the popup should be shown.
389 EXPECT_TRUE(CanOpenColorChooser());
390
391 Settings* settings = GetSettings();
392 settings->SetPagePopupsSuppressed(true);
393
394 EXPECT_FALSE(CanOpenColorChooser());
395
396 settings->SetPagePopupsSuppressed(false);
397 EXPECT_TRUE(CanOpenColorChooser());
398 }
399
400 TEST_F(PagePopupSuppressionTest, SuppressDateTimeChooser) {
401 // By default, the popup should be shown.
402 EXPECT_TRUE(CanOpenDateTimeChooser());
403
404 Settings* settings = GetSettings();
405 settings->SetPagePopupsSuppressed(true);
406
407 EXPECT_FALSE(CanOpenDateTimeChooser());
408
409 settings->SetPagePopupsSuppressed(false);
410 EXPECT_TRUE(CanOpenDateTimeChooser());
411 }
412
279 } // namespace blink 413 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698