Home | History | Annotate | Download | only in tests
      1 // Copyright (c) 2012 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 #include "ppapi/tests/test_flash_fullscreen.h"
      6 
      7 #include <stdio.h>
      8 #include <string.h>
      9 #include <string>
     10 
     11 #include "ppapi/c/dev/ppb_testing_dev.h"
     12 #include "ppapi/c/private/ppb_flash_fullscreen.h"
     13 #include "ppapi/cpp/graphics_2d.h"
     14 #include "ppapi/cpp/instance.h"
     15 #include "ppapi/cpp/module.h"
     16 #include "ppapi/cpp/point.h"
     17 #include "ppapi/cpp/private/flash_fullscreen.h"
     18 #include "ppapi/cpp/rect.h"
     19 #include "ppapi/cpp/size.h"
     20 #include "ppapi/tests/test_utils.h"
     21 #include "ppapi/tests/testing_instance.h"
     22 
     23 REGISTER_TEST_CASE(FlashFullscreen);
     24 
     25 namespace {
     26 
     27 bool IsFullscreenView(const pp::Rect& position,
     28                       const pp::Rect& clip,
     29                       const pp::Size& screen_size) {
     30   return (position.point() == pp::Point(0, 0) &&
     31           position.size() == screen_size &&
     32           clip.point() == pp::Point(0, 0) &&
     33           clip.size() == screen_size);
     34 }
     35 
     36 }  // namespace
     37 
     38 TestFlashFullscreen::TestFlashFullscreen(TestingInstance* instance)
     39     : TestCase(instance),
     40       screen_mode_(instance),
     41       fullscreen_pending_(false),
     42       normal_pending_(false),
     43       fullscreen_event_(instance->pp_instance()),
     44       normal_event_(instance->pp_instance()) {
     45   screen_mode_.GetScreenSize(&screen_size_);
     46 }
     47 
     48 bool TestFlashFullscreen::Init() {
     49   return CheckTestingInterface();
     50 }
     51 
     52 void TestFlashFullscreen::RunTests(const std::string& filter) {
     53   RUN_TEST(GetScreenSize, filter);
     54   RUN_TEST(NormalToFullscreenToNormal, filter);
     55 }
     56 
     57 std::string TestFlashFullscreen::TestGetScreenSize() {
     58   if (screen_size_.width() < 320 || screen_size_.width() > 2560)
     59     return ReportError("screen_size.width()", screen_size_.width());
     60   if (screen_size_.height() < 200 || screen_size_.height() > 2048)
     61     return ReportError("screen_size.height()", screen_size_.height());
     62   PASS();
     63 }
     64 
     65 std::string TestFlashFullscreen::TestNormalToFullscreenToNormal() {
     66   // 0. Start in normal mode.
     67   if (screen_mode_.IsFullscreen())
     68     return ReportError("IsFullscreen() at start", true);
     69 
     70   // 1. Switch to fullscreen.
     71   // The transition is asynchronous and ends at the next DidChangeView().
     72   // No graphics devices can be bound while in transition.
     73   fullscreen_pending_ = true;
     74   if (!screen_mode_.SetFullscreen(true))
     75     return ReportError("SetFullscreen(true) in normal", false);
     76   pp::Graphics2D graphics2d_fullscreen(instance_, pp::Size(10, 10), false);
     77   if (graphics2d_fullscreen.is_null())
     78     return "Failed to create graphics2d_fullscreen";
     79   // The out-of-process proxy is asynchronous, so testing for the following
     80   // conditions is flaky and can only be done reliably in-process.
     81   if (!testing_interface_->IsOutOfProcess()) {
     82     if (instance_->BindGraphics(graphics2d_fullscreen))
     83       return ReportError("BindGraphics() in fullscreen transition", true);
     84     if (screen_mode_.IsFullscreen())
     85       return ReportError("IsFullscreen() in fullscreen transtion", true);
     86   }
     87 
     88   // DidChangeView() will call the callback once in fullscreen mode.
     89   fullscreen_event_.Wait();
     90   if (fullscreen_pending_)
     91     return "fullscreen_pending_ has not been reset";
     92   if (!screen_mode_.IsFullscreen())
     93     return ReportError("IsFullscreen() in fullscreen", false);
     94   if (!instance_->BindGraphics(graphics2d_fullscreen))
     95     return ReportError("BindGraphics() in fullscreen", false);
     96 
     97   // 2. Stay in fullscreen. No change.
     98   if (!screen_mode_.SetFullscreen(true))
     99     return ReportError("SetFullscreen(true) in fullscreen", false);
    100   if (!screen_mode_.IsFullscreen())
    101     return ReportError("IsFullscreen() in fullscreen^2", false);
    102 
    103   // 3. Switch to normal.
    104   // The transition is synchronous in-process and asynchornous out-of-process
    105   // because proxied IsFullscreen saves a roundtrip by relying on information
    106   // communicated via a previous call to DidChangeView.
    107   // Graphics devices can be bound right away.
    108   normal_pending_ = true;
    109   if (!screen_mode_.SetFullscreen(false))
    110     return ReportError("SetFullscreen(false) in fullscreen", false);
    111   pp::Graphics2D graphics2d_normal(instance_, pp::Size(15, 15), false);
    112   if (graphics2d_normal.is_null())
    113     return "Failed to create graphics2d_normal";
    114   if (!instance_->BindGraphics(graphics2d_normal))
    115     return ReportError("BindGraphics() in normal transition", false);
    116   if (testing_interface_->IsOutOfProcess()) {
    117     if (!screen_mode_.IsFullscreen())
    118       return ReportError("IsFullscreen() in normal transition", false);
    119     normal_event_.Wait();
    120     if (normal_pending_)
    121       return "normal_pending_ has not been reset";
    122   }
    123   if (screen_mode_.IsFullscreen())
    124     return ReportError("IsFullscreen() in normal", true);
    125 
    126   // 4. Stay in normal. No change.
    127   if (!screen_mode_.SetFullscreen(false))
    128     return ReportError("SetFullscreen(false) in normal", false);
    129   if (screen_mode_.IsFullscreen())
    130     return ReportError("IsFullscreen() in normal^2", true);
    131 
    132   PASS();
    133 }
    134 
    135 // Transition to fullscreen is asynchornous ending at DidChangeView.
    136 // Transition to normal is synchronous in-process and asynchronous
    137 // out-of-process ending at DidChangeView.
    138 void TestFlashFullscreen::DidChangeView(const pp::View& view) {
    139   pp::Rect position = view.GetRect();
    140   pp::Rect clip = view.GetClipRect();
    141   if (fullscreen_pending_ && IsFullscreenView(position, clip, screen_size_)) {
    142     fullscreen_pending_ = false;
    143     fullscreen_event_.Signal();
    144   } else if (normal_pending_ &&
    145              !IsFullscreenView(position, clip, screen_size_)) {
    146     normal_pending_ = false;
    147     if (testing_interface_->IsOutOfProcess())
    148       normal_event_.Signal();
    149   }
    150 }
    151