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

Side by Side Diff: content/browser/device_orientation/device_orientation_browsertest.cc

Issue 10831023: Move over a bunch of tests from browser_tests to content_browsertests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/file_path.h" 6 #include "base/file_path.h"
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_tabstrip.h"
10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "chrome/test/base/ui_test_utils.h"
12 #include "content/browser/device_orientation/orientation.h" 8 #include "content/browser/device_orientation/orientation.h"
13 #include "content/browser/device_orientation/provider.h" 9 #include "content/browser/device_orientation/provider.h"
14 #include "content/public/browser/web_contents.h" 10 #include "content/public/browser/web_contents.h"
15 #include "content/public/common/content_switches.h" 11 #include "content/public/common/content_switches.h"
12 #include "content/shell/shell.h"
13 #include "content/test/content_browser_test.h"
14 #include "content/test/content_browser_test_utils.h"
16 15
17 namespace device_orientation { 16 namespace device_orientation {
18 17
19 class MockProvider : public Provider { 18 class MockProvider : public Provider {
20 public: 19 public:
21 explicit MockProvider(const Orientation& orientation) 20 explicit MockProvider(const Orientation& orientation)
22 : orientation_(orientation), 21 : orientation_(orientation),
23 added_observer_(false), 22 added_observer_(false),
24 removed_observer_(false) {} 23 removed_observer_(false) {}
25 24
26 virtual void AddObserver(Observer* observer) { 25 virtual void AddObserver(Observer* observer) {
27 added_observer_ = true; 26 added_observer_ = true;
28 observer->OnOrientationUpdate(orientation_); 27 observer->OnOrientationUpdate(orientation_);
29 } 28 }
30 virtual void RemoveObserver(Observer* observer) { 29 virtual void RemoveObserver(Observer* observer) {
31 removed_observer_ = true; 30 removed_observer_ = true;
32 } 31 }
33 32
34 Orientation orientation_; 33 Orientation orientation_;
35 bool added_observer_; 34 bool added_observer_;
36 bool removed_observer_; 35 bool removed_observer_;
37 36
38 private: 37 private:
39 virtual ~MockProvider() {} 38 virtual ~MockProvider() {}
40 }; 39 };
41 40
42 class DeviceOrientationBrowserTest : public InProcessBrowserTest { 41 class DeviceOrientationBrowserTest : public content::ContentBrowserTest {
43 public: 42 public:
44 // From InProcessBrowserTest. 43 // From ContentBrowserTest.
45 virtual void SetUpCommandLine(CommandLine* command_line) { 44 virtual void SetUpCommandLine(CommandLine* command_line) {
46 EXPECT_TRUE(!command_line->HasSwitch(switches::kDisableDeviceOrientation)); 45 EXPECT_TRUE(!command_line->HasSwitch(switches::kDisableDeviceOrientation));
47 } 46 }
48
49 GURL testUrl(const FilePath::CharType* filename) {
50 const FilePath kTestDir(FILE_PATH_LITERAL("device_orientation"));
51 return ui_test_utils::GetTestUrl(kTestDir, FilePath(filename));
52 }
53 }; 47 };
54 48
55 // crbug.com/113952 49 // crbug.com/113952
56 IN_PROC_BROWSER_TEST_F(DeviceOrientationBrowserTest, BasicTest) { 50 IN_PROC_BROWSER_TEST_F(DeviceOrientationBrowserTest, BasicTest) {
57 Orientation test_orientation; 51 Orientation test_orientation;
58 test_orientation.set_alpha(1); 52 test_orientation.set_alpha(1);
59 test_orientation.set_beta(2); 53 test_orientation.set_beta(2);
60 test_orientation.set_gamma(3); 54 test_orientation.set_gamma(3);
61 test_orientation.set_absolute(true); 55 test_orientation.set_absolute(true);
62 scoped_refptr<MockProvider> provider(new MockProvider(test_orientation)); 56 scoped_refptr<MockProvider> provider(new MockProvider(test_orientation));
63 Provider::SetInstanceForTests(provider.get()); 57 Provider::SetInstanceForTests(provider.get());
64 58
65 // The test page will register an event handler for orientation events, 59 // The test page will register an event handler for orientation events,
66 // expects to get an event with kTestOrientation orientation, 60 // expects to get an event with kTestOrientation orientation,
67 // then removes the event handler and navigates to #pass. 61 // then removes the event handler and navigates to #pass.
68 GURL test_url = testUrl(FILE_PATH_LITERAL("device_orientation_test.html")); 62 GURL test_url = content::GetTestUrl(
69 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), 63 "device_orientation", "device_orientation_test.html");
70 test_url, 64 content::NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2);
71 2);
72 65
73 // Check that the page got the event it expected and that the provider 66 // Check that the page got the event it expected and that the provider
74 // saw requests for adding and removing an observer. 67 // saw requests for adding and removing an observer.
75 EXPECT_EQ("pass", chrome::GetActiveWebContents(browser())->GetURL().ref()); 68 EXPECT_EQ("pass", shell()->web_contents()->GetURL().ref());
76 EXPECT_TRUE(provider->added_observer_); 69 EXPECT_TRUE(provider->added_observer_);
77 EXPECT_TRUE(provider->removed_observer_); 70 EXPECT_TRUE(provider->removed_observer_);
78 } 71 }
79 72
80 } // namespace device_orientation 73 } // namespace device_orientation
OLDNEW
« no previous file with comments | « content/browser/child_process_security_policy_browsertest.cc ('k') | content/browser/dom_storage/dom_storage_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698