summaryrefslogtreecommitdiffstats
path: root/ash/wm/video_detector_unittest.cc
diff options
context:
space:
mode:
authorrharrison@chromium.org <rharrison@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-06 19:28:40 +0000
committerrharrison@chromium.org <rharrison@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-06 19:28:40 +0000
commit781a4d3dc85d3833f3c2429bed24a6ad90d940dd (patch)
tree32905ded37efa40ccbd9601584e80542fb58386d /ash/wm/video_detector_unittest.cc
parent8d8aefc2466f0638cea7130b66cfea1adbe6f071 (diff)
downloadchromium_src-781a4d3dc85d3833f3c2429bed24a6ad90d940dd.zip
chromium_src-781a4d3dc85d3833f3c2429bed24a6ad90d940dd.tar.gz
chromium_src-781a4d3dc85d3833f3c2429bed24a6ad90d940dd.tar.bz2
Add is_fullscreen to video updates
This is a re-attempt at http://codereview.chromium.org/10905026/, which ended up being reverted. The crash that caused the revert was actually due to powerd not being able to parse the protobuf correctly. https://gerrit.chromium.org/gerrit/32243/ corrects this issue, so once that CL lands this CL is good to go. I confirmed the combination of CLs works correctly. This is the original CL description: This adds a boolean to the video update message sent to powerd that indicates whether or not the video playing window is fullscreen'd. This is information used in powerd for controlling when to enable/disable keyboard backlights. Specifically if video is playing and fullscreen we assume that the user is doing something like watching a movie so will disable backlight. An additional change that I have made is to convert the message being sent from an int64 to a protobuffer that contains a int64 and a boolean. Currently, since the receiver of this message does not live in the same repo it means that everytime one wants to change the message format there is a small window where bad builds can be generated or one has to land two changes to the other repo, one to add handling of the new message format and then a second one to remove the old format. Converting to a protobuffer means that for common cases this issues are removed. This CL depends on CLs for power_manager (https://gerrit.chromium.org/gerrit/32092/), one for system_api (https://gerrit.chromium.org/gerrit/31916), and a DEPS roll(http://codereview.chromium.org/10915032/). There will be future CLs for power_manager that will use this information and more thourghly tests this code. BUG=chrome-os-partner:9203 TEST=Run updated unittests. Confirm there is no messages in the cros logs about this method being mishandled. Make sure that powerd is not crashing due to protocol buffer processing failing. Review URL: https://chromiumcodereview.appspot.com/10916123 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@155224 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/wm/video_detector_unittest.cc')
-rw-r--r--ash/wm/video_detector_unittest.cc58
1 files changed, 54 insertions, 4 deletions
diff --git a/ash/wm/video_detector_unittest.cc b/ash/wm/video_detector_unittest.cc
index 2a7ffd9..4c5d028 100644
--- a/ash/wm/video_detector_unittest.cc
+++ b/ash/wm/video_detector_unittest.cc
@@ -11,6 +11,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/time.h"
#include "third_party/skia/include/core/SkColor.h"
+#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/window_types.h"
#include "ui/aura/root_window.h"
#include "ui/aura/test/test_windows.h"
@@ -24,17 +25,37 @@ namespace test {
// video is playing.
class TestVideoDetectorObserver : public VideoDetectorObserver {
public:
- TestVideoDetectorObserver() : num_invocations_(0) {}
+ TestVideoDetectorObserver() : num_invocations_(0),
+ num_fullscreens_(0),
+ num_not_fullscreens_(0) {}
int num_invocations() const { return num_invocations_; }
- void reset_stats() { num_invocations_ = 0; }
+ int num_fullscreens() const { return num_fullscreens_; }
+ int num_not_fullscreens() const { return num_not_fullscreens_; }
+ void reset_stats() {
+ num_invocations_ = 0;
+ num_fullscreens_ = 0;
+ num_not_fullscreens_ = 0;
+ }
// VideoDetectorObserver implementation.
- virtual void OnVideoDetected() OVERRIDE { num_invocations_++; }
+ virtual void OnVideoDetected(bool is_fullscreen) OVERRIDE {
+ num_invocations_++;
+ if (is_fullscreen)
+ num_fullscreens_++;
+ else
+ num_not_fullscreens_++;
+ }
private:
// Number of times that OnVideoDetected() has been called.
int num_invocations_;
+ // Number of times that OnVideoDetected() has been called with is_fullscreen
+ // == true.
+ int num_fullscreens_;
+ // Number of times that OnVideoDetected() has been called with is_fullscreen
+ // == false.
+ int num_not_fullscreens_;
DISALLOW_COPY_AND_ASSIGN(TestVideoDetectorObserver);
};
@@ -104,8 +125,12 @@ TEST_F(VideoDetectorTest, Basic) {
// additional updates.
detector_->OnWindowPaintScheduled(window.get(), update_region);
EXPECT_EQ(1, observer_->num_invocations());
+ EXPECT_EQ(0, observer_->num_fullscreens());
+ EXPECT_EQ(1, observer_->num_not_fullscreens());
detector_->OnWindowPaintScheduled(window.get(), update_region);
EXPECT_EQ(1, observer_->num_invocations());
+ EXPECT_EQ(0, observer_->num_fullscreens());
+ EXPECT_EQ(1, observer_->num_not_fullscreens());
// Spread out the frames over two seconds; we shouldn't detect video.
observer_->reset_stats();
@@ -144,6 +169,8 @@ TEST_F(VideoDetectorTest, WindowNotVisible) {
for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
detector_->OnWindowPaintScheduled(window.get(), update_region);
EXPECT_EQ(1, observer_->num_invocations());
+ EXPECT_EQ(0, observer_->num_fullscreens());
+ EXPECT_EQ(1, observer_->num_not_fullscreens());
// We also shouldn't report video in a window that's fully offscreen.
observer_->reset_stats();
@@ -177,6 +204,8 @@ TEST_F(VideoDetectorTest, MultipleWindows) {
for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
detector_->OnWindowPaintScheduled(window2.get(), update_region);
EXPECT_EQ(1, observer_->num_invocations());
+ EXPECT_EQ(0, observer_->num_fullscreens());
+ EXPECT_EQ(1, observer_->num_not_fullscreens());
}
// Test that the observer receives repeated notifications.
@@ -192,7 +221,8 @@ TEST_F(VideoDetectorTest, RepeatedNotifications) {
for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
detector_->OnWindowPaintScheduled(window.get(), update_region);
EXPECT_EQ(1, observer_->num_invocations());
-
+ EXPECT_EQ(0, observer_->num_fullscreens());
+ EXPECT_EQ(1, observer_->num_not_fullscreens());
// Let enough time pass that a second notification should be sent.
observer_->reset_stats();
AdvanceTime(base::TimeDelta::FromSeconds(
@@ -200,6 +230,26 @@ TEST_F(VideoDetectorTest, RepeatedNotifications) {
for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
detector_->OnWindowPaintScheduled(window.get(), update_region);
EXPECT_EQ(1, observer_->num_invocations());
+ EXPECT_EQ(0, observer_->num_fullscreens());
+ EXPECT_EQ(1, observer_->num_not_fullscreens());
+}
+
+// Test that the observer receives a true value when the window is fullscreen.
+TEST_F(VideoDetectorTest, FullscreenWindow) {
+ gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768));
+ scoped_ptr<aura::Window> window(
+ aura::test::CreateTestWindow(SK_ColorRED, 12345, window_bounds, NULL));
+ window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
+
+ gfx::Rect update_region(
+ gfx::Point(),
+ gfx::Size(VideoDetector::kMinUpdateWidth,
+ VideoDetector::kMinUpdateHeight));
+ for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
+ detector_->OnWindowPaintScheduled(window.get(), update_region);
+ EXPECT_EQ(1, observer_->num_invocations());
+ EXPECT_EQ(1, observer_->num_fullscreens());
+ EXPECT_EQ(0, observer_->num_not_fullscreens());
}
} // namespace test