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

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: added explanatory comment. 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 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"
38 #include "platform/Language.h"
35 #include "public/platform/WebInputEvent.h" 39 #include "public/platform/WebInputEvent.h"
36 #include "public/web/WebFrameClient.h" 40 #include "public/web/WebFrameClient.h"
37 #include "public/web/WebLocalFrame.h" 41 #include "public/web/WebLocalFrame.h"
38 #include "public/web/WebView.h" 42 #include "public/web/WebView.h"
39 #include "public/web/WebViewClient.h" 43 #include "public/web/WebViewClient.h"
40 #include "testing/gtest/include/gtest/gtest.h" 44 #include "testing/gtest/include/gtest/gtest.h"
41 #include "web/ChromeClientImpl.h" 45 #include "web/ChromeClientImpl.h"
42 #include "web/WebLocalFrameImpl.h" 46 #include "web/WebLocalFrameImpl.h"
43 #include "web/tests/FrameTestHelpers.h" 47 #include "web/tests/FrameTestHelpers.h"
44 48
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 TEST_F(CreateWindowTest, CreateWindowFromSuspendedPage) { 273 TEST_F(CreateWindowTest, CreateWindowFromSuspendedPage) {
270 ScopedPageSuspender suspender; 274 ScopedPageSuspender suspender;
271 LocalFrame* frame = ToWebLocalFrameImpl(main_frame_)->GetFrame(); 275 LocalFrame* frame = ToWebLocalFrameImpl(main_frame_)->GetFrame();
272 FrameLoadRequest request(frame->GetDocument()); 276 FrameLoadRequest request(frame->GetDocument());
273 WindowFeatures features; 277 WindowFeatures features;
274 EXPECT_EQ(nullptr, 278 EXPECT_EQ(nullptr,
275 chrome_client_impl_->CreateWindow( 279 chrome_client_impl_->CreateWindow(
276 frame, request, features, kNavigationPolicyNewForegroundTab)); 280 frame, request, features, kNavigationPolicyNewForegroundTab));
277 } 281 }
278 282
283 class FakeColorChooserClient
284 : public GarbageCollectedFinalized<FakeColorChooserClient>,
285 public ColorChooserClient {
286 public:
287 FakeColorChooserClient(Element* owner_element)
288 : owner_element_(owner_element) {}
289 ~FakeColorChooserClient() override {}
290
291 DEFINE_INLINE_VIRTUAL_TRACE() {
292 visitor->Trace(owner_element_);
293 ColorChooserClient::Trace(visitor);
294 }
295
296 USING_GARBAGE_COLLECTED_MIXIN(FakeColorChooserClient)
297
298 // ColorChooserClient
299 void DidChooseColor(const Color& color) override {}
300 void DidEndChooser() override {}
301 Element& OwnerElement() const override { return *owner_element_; }
302 IntRect ElementRectRelativeToViewport() const override { return IntRect(); }
303 Color CurrentColor() override { return Color(); }
304 bool ShouldShowSuggestions() const override { return false; }
305 Vector<ColorSuggestion> Suggestions() const override {
306 return Vector<ColorSuggestion>();
307 }
308
309 private:
310 Member<Element> owner_element_;
311 };
312
313 class FakeDateTimeChooserClient
314 : public GarbageCollectedFinalized<FakeDateTimeChooserClient>,
315 public DateTimeChooserClient {
316 public:
317 FakeDateTimeChooserClient(Element* owner_element)
318 : owner_element_(owner_element) {}
319 ~FakeDateTimeChooserClient() override {}
320
321 DEFINE_INLINE_VIRTUAL_TRACE() {
322 visitor->Trace(owner_element_);
323 DateTimeChooserClient::Trace(visitor);
324 }
325
326 USING_GARBAGE_COLLECTED_MIXIN(FakeDateTimeChooserClient)
327
328 // DateTimeChooserClient
329 Element& OwnerElement() const override { return *owner_element_; }
330 void DidChooseValue(const String&) override {}
331 void DidChooseValue(double) override {}
332 void DidEndChooser() override {}
333
334 private:
335 Member<Element> owner_element_;
336 };
337
338 class PagePopupSuppressionTest : public testing::Test {
339 public:
340 PagePopupSuppressionTest() {}
341
342 bool CanOpenColorChooser() {
343 LocalFrame* frame = ToWebLocalFrameImpl(main_frame_)->GetFrame();
344 Color color;
345 return !!chrome_client_impl_->OpenColorChooser(frame, color_chooser_client_,
346 color);
347 }
348
349 bool CanOpenDateTimeChooser() {
350 DateTimeChooserParameters params;
351 params.locale = DefaultLanguage();
352 return !!chrome_client_impl_->OpenDateTimeChooser(date_time_chooser_client_,
353 params);
354 }
355
356 Settings* GetSettings() {
357 LocalFrame* frame = ToWebLocalFrameImpl(main_frame_)->GetFrame();
358 return frame->GetDocument()->GetSettings();
359 }
360
361 protected:
362 void SetUp() override {
363 web_view_ = static_cast<WebViewBase*>(
364 WebViewBase::Create(&web_view_client_, kWebPageVisibilityStateVisible));
365 main_frame_ = WebLocalFrame::Create(WebTreeScopeType::kDocument,
366 &web_frame_client_, nullptr, nullptr);
367 web_view_->SetMainFrame(main_frame_);
368 chrome_client_impl_ =
369 ToChromeClientImpl(&web_view_->GetPage()->GetChromeClient());
370 LocalFrame* frame = ToWebLocalFrameImpl(main_frame_)->GetFrame();
371 color_chooser_client_ =
372 new FakeColorChooserClient(frame->GetDocument()->documentElement());
373 date_time_chooser_client_ =
374 new FakeDateTimeChooserClient(frame->GetDocument()->documentElement());
375 }
376
377 void TearDown() override { web_view_->Close(); }
378
379 protected:
380 FrameTestHelpers::TestWebViewClient web_view_client_;
381 WebViewBase* web_view_ = nullptr;
382 WebLocalFrame* main_frame_ = nullptr;
383 FrameTestHelpers::TestWebFrameClient web_frame_client_;
384 Persistent<ChromeClientImpl> chrome_client_impl_;
385 Persistent<FakeColorChooserClient> color_chooser_client_;
386 Persistent<FakeDateTimeChooserClient> date_time_chooser_client_;
387 };
388
389 TEST_F(PagePopupSuppressionTest, SuppressColorChooser) {
390 // By default, the popup should be shown.
391 EXPECT_TRUE(CanOpenColorChooser());
392
393 Settings* settings = GetSettings();
394 settings->SetPagePopupsSuppressed(true);
395
396 EXPECT_FALSE(CanOpenColorChooser());
397
398 settings->SetPagePopupsSuppressed(false);
399 EXPECT_TRUE(CanOpenColorChooser());
400 }
401
402 TEST_F(PagePopupSuppressionTest, SuppressDateTimeChooser) {
403 // By default, the popup should be shown.
404 EXPECT_TRUE(CanOpenDateTimeChooser());
405
406 Settings* settings = GetSettings();
407 settings->SetPagePopupsSuppressed(true);
408
409 EXPECT_FALSE(CanOpenDateTimeChooser());
410
411 settings->SetPagePopupsSuppressed(false);
412 EXPECT_TRUE(CanOpenDateTimeChooser());
413 }
414
279 } // namespace blink 415 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebSettingsImpl.cpp ('k') | third_party/WebKit/public/web/WebSettings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698