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

Unified Diff: content/renderer/screen_orientation/screen_orientation_dispatcher_unittest.cc

Issue 164913004: Chromium plumbing for Screen Orientation API orientationchange events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use enum + android backend Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/screen_orientation/screen_orientation_dispatcher_unittest.cc
diff --git a/content/renderer/screen_orientation/screen_orientation_dispatcher_unittest.cc b/content/renderer/screen_orientation/screen_orientation_dispatcher_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b4d929c16719ed1f139b77e70730b3c6a454eb0e
--- /dev/null
+++ b/content/renderer/screen_orientation/screen_orientation_dispatcher_unittest.cc
@@ -0,0 +1,100 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "screen_orientation_dispatcher.h"
+
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "content/common/screen_orientation_messages.h"
+#include "content/public/test/mock_render_thread.h"
+#include "content/public/test/test_utils.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/public/platform/WebScreenOrientationListener.h"
+
+namespace content {
+
+class MockScreenOrientationListener :
+ public blink::WebScreenOrientationListener {
+ public:
+ MockScreenOrientationListener();
+ virtual ~MockScreenOrientationListener() { }
jochen (gone - plz use gerrit) 2014/02/24 14:08:26 no space inside {}
mlamouri (slow - plz ping) 2014/02/24 14:20:21 Done.
+
+ virtual void didChangeScreenOrientation(blink::WebScreenOrientation) OVERRIDE;
+
+ bool did_change_screen_orientation_;
jochen (gone - plz use gerrit) 2014/02/24 14:08:26 members should be private. please use getters to a
mlamouri (slow - plz ping) 2014/02/24 14:20:21 Done.
+ blink::WebScreenOrientation screen_orientation_;
+};
jochen (gone - plz use gerrit) 2014/02/24 14:08:26 disallow copy/assign
mlamouri (slow - plz ping) 2014/02/24 14:20:21 Done.
+
+MockScreenOrientationListener::MockScreenOrientationListener()
+ : did_change_screen_orientation_(false),
+ screen_orientation_(blink::WebScreenOrientationPortraitPrimary) {
+}
+
+void MockScreenOrientationListener::didChangeScreenOrientation(
+ blink::WebScreenOrientation orientation) {
+ did_change_screen_orientation_ = true;
+ screen_orientation_ = orientation;
+}
+
+class ScreenOrientationDispatcherTest : public testing::Test {
+ protected:
+ virtual void SetUp() OVERRIDE {
+ render_thread_.reset(new MockRenderThread);
+ listener_.reset(new MockScreenOrientationListener);
+ dispatcher_.reset(new ScreenOrientationDispatcher(render_thread_.get()));
+ dispatcher_->setListener(listener_.get());
+ }
+
+ scoped_ptr<MockRenderThread> render_thread_;
+ scoped_ptr<MockScreenOrientationListener> listener_;
+ scoped_ptr<ScreenOrientationDispatcher> dispatcher_;
+};
+
+TEST_F(ScreenOrientationDispatcherTest, ListensToMessages) {
+ EXPECT_TRUE(render_thread_->observers().HasObserver(dispatcher_.get()));
+
+ render_thread_->OnControlMessageReceived(
+ ScreenOrientationMsg_OrientationChange(
+ blink::WebScreenOrientationPortraitPrimary));
+
+ EXPECT_TRUE(listener_->did_change_screen_orientation_);
+}
+
+TEST_F(ScreenOrientationDispatcherTest, NullListener) {
+ dispatcher_->setListener(NULL);
+
+ render_thread_->OnControlMessageReceived(
+ ScreenOrientationMsg_OrientationChange(
+ blink::WebScreenOrientationPortraitPrimary));
+
+ EXPECT_FALSE(listener_->did_change_screen_orientation_);
+}
+
+TEST_F(ScreenOrientationDispatcherTest, ValidValues) {
+ render_thread_->OnControlMessageReceived(
+ ScreenOrientationMsg_OrientationChange(
+ blink::WebScreenOrientationPortraitPrimary));
+ EXPECT_EQ(blink::WebScreenOrientationPortraitPrimary,
+ listener_->screen_orientation_);
+
+ render_thread_->OnControlMessageReceived(
+ ScreenOrientationMsg_OrientationChange(
+ blink::WebScreenOrientationLandscapePrimary));
+ EXPECT_EQ(blink::WebScreenOrientationLandscapePrimary,
+ listener_->screen_orientation_);
+
+ render_thread_->OnControlMessageReceived(
+ ScreenOrientationMsg_OrientationChange(
+ blink::WebScreenOrientationPortraitSecondary));
+ EXPECT_EQ(blink::WebScreenOrientationPortraitSecondary,
+ listener_->screen_orientation_);
+
+ render_thread_->OnControlMessageReceived(
+ ScreenOrientationMsg_OrientationChange(
+ blink::WebScreenOrientationLandscapeSecondary));
+ EXPECT_EQ(blink::WebScreenOrientationLandscapeSecondary,
+ listener_->screen_orientation_);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698