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

Unified Diff: content/browser/screen_orientation/screen_orientation_dispatcher_host_unittest.cc

Issue 177793003: Chromium plumbing for Screen Orientation API lock/unlock. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chromium_plumbing_screen_orientation
Patch Set: with tests 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/browser/screen_orientation/screen_orientation_dispatcher_host_unittest.cc
diff --git a/content/browser/screen_orientation/screen_orientation_dispatcher_host_unittest.cc b/content/browser/screen_orientation/screen_orientation_dispatcher_host_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..65fe19a218043f515915188269181115b2d146b6
--- /dev/null
+++ b/content/browser/screen_orientation/screen_orientation_dispatcher_host_unittest.cc
@@ -0,0 +1,129 @@
+// 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 <list>
+
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "content/browser/screen_orientation/screen_orientation_dispatcher_host.h"
+#include "content/browser/screen_orientation/screen_orientation_provider.h"
+#include "content/common/screen_orientation_messages.h"
+#include "content/public/test/test_utils.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace content {
+
+class MockScreenOrientationProvider : public ScreenOrientationProvider {
+ public:
+ MockScreenOrientationProvider()
+ : orientations_(0) ,
+ unlock_called_(false)
+ {}
+
+ virtual void LockOrientation(
+ blink::WebScreenOrientations orientations) OVERRIDE {
+ orientations_ = orientations;
+
+ }
+
+ virtual void UnlockOrientation() OVERRIDE {
+ unlock_called_ = true;
+ }
+
+ blink::WebScreenOrientations orientations() const {
+ return orientations_;
+ }
+
+ bool unlock_called() const {
+ return unlock_called_;
+ }
+
+ virtual ~MockScreenOrientationProvider() {}
+
+ private:
+ blink::WebScreenOrientations orientations_;
+ bool unlock_called_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockScreenOrientationProvider);
+};
+
+class ScreenOrientationDispatcherHostTest : public testing::Test {
+ protected:
+ virtual void SetUp() OVERRIDE {
+ provider_ = new MockScreenOrientationProvider();
+
+ dispatcher_ = new ScreenOrientationDispatcherHost();
+ dispatcher_->SetProviderForTests(provider_);
+ }
+
+ // The dispatcher_ owns the provider_ but we still want to access it.
+ MockScreenOrientationProvider* provider_;
+ scoped_refptr<ScreenOrientationDispatcherHost> dispatcher_;
+};
+
+// Test that a NULL provider is correctly handled.
+TEST_F(ScreenOrientationDispatcherHostTest, NullProvider) {
+ dispatcher_->SetProviderForTests(NULL);
+
+ bool message_was_ok = false;
+ bool message_was_handled = dispatcher_->OnMessageReceived(
+ ScreenOrientationMsg_Lock(blink::WebScreenOrientationPortraitPrimary),
+ &message_was_ok);
+
+ EXPECT_TRUE(message_was_ok);
+ EXPECT_TRUE(message_was_handled);
+}
+
+// Test that when receiving a lock message, it is correctly dispatched to the
+// ScreenOrientationProvider.
+TEST_F(ScreenOrientationDispatcherHostTest, ProviderLock) {
+ std::list<blink::WebScreenOrientations> orientationsToTest = {
+ // The basic types.
+ blink::WebScreenOrientationPortraitPrimary,
+ blink::WebScreenOrientationPortraitSecondary,
+ blink::WebScreenOrientationLandscapePrimary,
+ blink::WebScreenOrientationLandscapeSecondary,
+ // Some unions.
+ blink::WebScreenOrientationLandscapePrimary |
+ blink::WebScreenOrientationPortraitPrimary,
+ blink::WebScreenOrientationLandscapePrimary |
+ blink::WebScreenOrientationPortraitSecondary,
+ blink::WebScreenOrientationPortraitPrimary |
+ blink::WebScreenOrientationPortraitSecondary |
+ blink::WebScreenOrientationLandscapePrimary |
+ blink::WebScreenOrientationLandscapeSecondary,
+ // Garbage values.
+ 0,
+ 100,
+ 42
+ };
+
+ for (std::list<blink::WebScreenOrientations>::const_iterator it =
+ orientationsToTest.begin(); it != orientationsToTest.end(); ++it) {
+ bool message_was_ok = false;
+ bool message_was_handled = false;
+ blink::WebScreenOrientations orientations = *it;
+
+ message_was_handled = dispatcher_->OnMessageReceived(
+ ScreenOrientationMsg_Lock(orientations), &message_was_ok);
+
+ EXPECT_TRUE(message_was_ok);
+ EXPECT_TRUE(message_was_handled);
+ EXPECT_EQ(orientations, provider_->orientations());
+ }
+}
+
+// Test that when receiving an unlock message, it is correctly dispatched to the
+// ScreenOrientationProvider.
+TEST_F(ScreenOrientationDispatcherHostTest, ProviderUnlock) {
+ bool message_was_ok = false;
+ bool message_was_handled = dispatcher_->OnMessageReceived(
+ ScreenOrientationMsg_Unlock(), &message_was_ok);
+
+ EXPECT_TRUE(message_was_ok);
+ EXPECT_TRUE(message_was_handled);
+ EXPECT_TRUE(provider_->unlock_called());
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698