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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/device_orientation/dispatcher_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 "base/command_line.h"
6 #include "base/file_path.h"
7 #include "base/ref_counted.h"
8 #include "chrome/browser/browser.h"
9 #include "chrome/browser/device_orientation/orientation.h"
10 #include "chrome/browser/device_orientation/provider.h"
11 #include "chrome/browser/tab_contents/tab_contents.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/test/in_process_browser_test.h"
14 #include "chrome/test/ui_test_utils.h"
15
16 namespace device_orientation {
17
18 class MockProvider : public Provider {
19 public:
20 explicit MockProvider(const Orientation& orientation)
21 : orientation_(orientation),
22 added_observer_(false),
23 removed_observer_(false) {}
24
25 virtual void AddObserver(Observer* observer) {
26 added_observer_ = true;
27 observer->OnOrientationUpdate(orientation_);
28 }
29 virtual void RemoveObserver(Observer* observer) {
30 removed_observer_ = true;
31 }
32 Orientation orientation_;
33 bool added_observer_;
34 bool removed_observer_;
35 };
36
37 class DeviceOrientationBrowserTest : public InProcessBrowserTest {
38 public:
39 // From InProcessBrowserTest.
40 virtual void SetUpCommandLine(CommandLine* command_line) {
41 command_line->AppendSwitch(switches::kEnableDeviceOrientation);
42 }
43
44 GURL testUrl(const FilePath::CharType* filename) {
45 const FilePath kTestDir(FILE_PATH_LITERAL("device_orientation"));
46 return ui_test_utils::GetTestUrl(kTestDir, FilePath(filename));
47 }
48 };
49
50 IN_PROC_BROWSER_TEST_F(DeviceOrientationBrowserTest, BasicTest) {
51 const Orientation kTestOrientation(true, 1, true, 2, true, 3);
52 scoped_refptr<MockProvider> provider = new MockProvider(kTestOrientation);
53 Provider::SetInstanceForTests(provider.get());
54
55 // The test page will register an event handler for orientation events,
56 // expects to get an event with kTestOrientation orientation,
57 // then removes the event handler and navigates to #pass.
58 GURL test_url = testUrl(FILE_PATH_LITERAL("device_orientation_test.html"));
59 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(),
60 test_url,
61 2);
62
63 // Check that the page got the event it expected and that the provider
64 // saw requests for adding and removing an observer.
65 EXPECT_EQ("pass", browser()->GetSelectedTabContents()->GetURL().ref());
66 EXPECT_TRUE(provider->added_observer_);
67 EXPECT_TRUE(provider->removed_observer_);
68 }
69
70 } // namespace device_orientation
OLDNEW
« 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