Drive: Add BatchableRequest subclass.
[chromium-blink-merge.git] / ppapi / tests / test_flash_fullscreen_for_browser_ui.cc
blob0e37339f43aa3a3c66cfc14c7c313180cd260948
1 // Copyright 2014 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.
5 #include "ppapi/tests/test_flash_fullscreen_for_browser_ui.h"
7 #include "ppapi/cpp/input_event.h"
8 #include "ppapi/cpp/instance.h"
9 #include "ppapi/cpp/rect.h"
10 #include "ppapi/tests/testing_instance.h"
12 REGISTER_TEST_CASE(FlashFullscreenForBrowserUI);
14 TestFlashFullscreenForBrowserUI::
15 TestFlashFullscreenForBrowserUI(TestingInstance* instance)
16 : TestCase(instance),
17 screen_mode_(instance),
18 view_change_event_(instance->pp_instance()),
19 num_trigger_events_(0),
20 callback_factory_(this) {
21 // This plugin should not be removed after this TestCase passes because
22 // browser UI testing requires it to remain and to be interactive.
23 instance_->set_remove_plugin(false);
26 TestFlashFullscreenForBrowserUI::~TestFlashFullscreenForBrowserUI() {
29 bool TestFlashFullscreenForBrowserUI::Init() {
30 return CheckTestingInterface();
33 void TestFlashFullscreenForBrowserUI::RunTests(const std::string& filter) {
34 RUN_TEST(EnterFullscreen, filter);
37 std::string TestFlashFullscreenForBrowserUI::TestEnterFullscreen() {
38 if (screen_mode_.IsFullscreen())
39 return ReportError("IsFullscreen() at start", true);
41 view_change_event_.Reset();
42 if (!screen_mode_.SetFullscreen(true))
43 return ReportError("SetFullscreen(true) in normal", false);
44 // DidChangeView() will call the callback once in fullscreen mode.
45 view_change_event_.Wait();
47 if (!screen_mode_.IsFullscreen())
48 return ReportError("IsFullscreen() in fullscreen", false);
50 const int32_t result =
51 instance_->RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE |
52 PP_INPUTEVENT_CLASS_KEYBOARD);
53 if (result != PP_OK)
54 return ReportError("RequestFilteringInputEvents() failed", result);
56 PASS();
59 void TestFlashFullscreenForBrowserUI::DidChangeView(const pp::View& view) {
60 compositor_ = pp::Compositor(instance_);
61 instance_->BindGraphics(compositor_);
62 layer_size_ = view.GetRect().size();
63 color_layer_ = compositor_.AddLayer();
64 Paint(PP_OK);
66 view_change_event_.Signal();
69 bool TestFlashFullscreenForBrowserUI::HandleInputEvent(
70 const pp::InputEvent& event) {
71 if (event.GetType() != PP_INPUTEVENT_TYPE_MOUSEDOWN &&
72 event.GetType() != PP_INPUTEVENT_TYPE_CHAR) {
73 return false;
76 ++num_trigger_events_;
78 return true;
81 void TestFlashFullscreenForBrowserUI::Paint(int32_t last_compositor_result) {
82 if (num_trigger_events_ == 0)
83 color_layer_.SetColor(0.0f, 1.0f, 0.0f, 1.0f, layer_size_);
84 else if (num_trigger_events_ % 2)
85 color_layer_.SetColor(1.0f, 0.0f, 0.0f, 1.0f, layer_size_);
86 else
87 color_layer_.SetColor(0.0f, 0.0f, 1.0f, 1.0f, layer_size_);
89 compositor_.CommitLayers(
90 callback_factory_.NewCallback(&TestFlashFullscreenForBrowserUI::Paint));