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

Unified Diff: chrome/browser/device_orientation/device_orientation_browsertest.cc

Issue 2858049: Chromium plumbing for Device Orientation. (Closed)
Patch Set: Fixes after try bot runs Created 10 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/device_orientation/dispatcher_host.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/device_orientation/device_orientation_browsertest.cc
diff --git a/chrome/browser/device_orientation/device_orientation_browsertest.cc b/chrome/browser/device_orientation/device_orientation_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..332316e737d3b6b520d9ab235993ad52e319cc04
--- /dev/null
+++ b/chrome/browser/device_orientation/device_orientation_browsertest.cc
@@ -0,0 +1,70 @@
+// Copyright (c) 2010 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 "base/command_line.h"
+#include "base/file_path.h"
+#include "base/ref_counted.h"
+#include "chrome/browser/browser.h"
+#include "chrome/browser/device_orientation/orientation.h"
+#include "chrome/browser/device_orientation/provider.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/test/in_process_browser_test.h"
+#include "chrome/test/ui_test_utils.h"
+
+namespace device_orientation {
+
+class MockProvider : public Provider {
+ public:
+ explicit MockProvider(const Orientation& orientation)
+ : orientation_(orientation),
+ added_observer_(false),
+ removed_observer_(false) {}
+
+ virtual void AddObserver(Observer* observer) {
+ added_observer_ = true;
+ observer->OnOrientationUpdate(orientation_);
+ }
+ virtual void RemoveObserver(Observer* observer) {
+ removed_observer_ = true;
+ }
+ Orientation orientation_;
+ bool added_observer_;
+ bool removed_observer_;
+};
+
+class DeviceOrientationBrowserTest : public InProcessBrowserTest {
+ public:
+ // From InProcessBrowserTest.
+ virtual void SetUpCommandLine(CommandLine* command_line) {
+ command_line->AppendSwitch(switches::kEnableDeviceOrientation);
+ }
+
+ GURL testUrl(const FilePath::CharType* filename) {
+ const FilePath kTestDir(FILE_PATH_LITERAL("device_orientation"));
+ return ui_test_utils::GetTestUrl(kTestDir, FilePath(filename));
+ }
+};
+
+IN_PROC_BROWSER_TEST_F(DeviceOrientationBrowserTest, BasicTest) {
+ const Orientation kTestOrientation(true, 1, true, 2, true, 3);
+ scoped_refptr<MockProvider> provider = new MockProvider(kTestOrientation);
+ Provider::SetInstanceForTests(provider.get());
+
+ // The test page will register an event handler for orientation events,
+ // expects to get an event with kTestOrientation orientation,
+ // then removes the event handler and navigates to #pass.
+ GURL test_url = testUrl(FILE_PATH_LITERAL("device_orientation_test.html"));
+ ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(),
+ test_url,
+ 2);
+
+ // Check that the page got the event it expected and that the provider
+ // saw requests for adding and removing an observer.
+ EXPECT_EQ("pass", browser()->GetSelectedTabContents()->GetURL().ref());
+ EXPECT_TRUE(provider->added_observer_);
+ EXPECT_TRUE(provider->removed_observer_);
+}
+
+} // namespace device_orientation
« no previous file with comments | « no previous file | chrome/browser/device_orientation/dispatcher_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698