OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // MediaGalleriesPrivate eject API browser tests. | 5 // MediaGalleriesPrivate eject API browser tests. |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 | 46 |
47 } // namespace | 47 } // namespace |
48 | 48 |
49 | 49 |
50 /////////////////////////////////////////////////////////////////////////////// | 50 /////////////////////////////////////////////////////////////////////////////// |
51 // MediaGalleriesPrivateEjectApiTest // | 51 // MediaGalleriesPrivateEjectApiTest // |
52 /////////////////////////////////////////////////////////////////////////////// | 52 /////////////////////////////////////////////////////////////////////////////// |
53 | 53 |
54 class MediaGalleriesPrivateEjectApiTest : public ExtensionApiTest { | 54 class MediaGalleriesPrivateEjectApiTest : public ExtensionApiTest { |
55 public: | 55 public: |
56 MediaGalleriesPrivateEjectApiTest() : device_id_(GetDeviceId()) {} | 56 MediaGalleriesPrivateEjectApiTest() |
57 : device_id_(GetDeviceId()), monitor_(NULL) {} | |
sky
2013/07/15 17:45:37
nit: when you wrap, each param on its own line.
Greg Billock
2013/07/15 20:00:18
Done.
| |
57 virtual ~MediaGalleriesPrivateEjectApiTest() {} | 58 virtual ~MediaGalleriesPrivateEjectApiTest() {} |
58 | 59 |
59 protected: | 60 protected: |
60 // ExtensionApiTest overrides. | 61 // ExtensionApiTest overrides. |
61 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 62 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
62 ExtensionApiTest::SetUpCommandLine(command_line); | 63 ExtensionApiTest::SetUpCommandLine(command_line); |
63 command_line->AppendSwitchASCII(switches::kWhitelistedExtensionID, | 64 command_line->AppendSwitchASCII(switches::kWhitelistedExtensionID, |
64 kTestExtensionId); | 65 kTestExtensionId); |
65 } | 66 } |
66 | 67 |
68 virtual void SetUpOnMainThread() OVERRIDE { | |
69 monitor_ = chrome::test::TestStorageMonitor::CreateForBrowserTests(); | |
70 ExtensionApiTest::SetUpOnMainThread(); | |
71 } | |
72 | |
67 content::RenderViewHost* GetHost() { | 73 content::RenderViewHost* GetHost() { |
68 const extensions::Extension* extension = | 74 const extensions::Extension* extension = |
69 LoadExtension(test_data_dir_.AppendASCII(kTestExtensionPath)); | 75 LoadExtension(test_data_dir_.AppendASCII(kTestExtensionPath)); |
70 return extensions::ExtensionSystem::Get(browser()->profile())-> | 76 return extensions::ExtensionSystem::Get(browser()->profile())-> |
71 process_manager()->GetBackgroundHostForExtension(extension->id())-> | 77 process_manager()->GetBackgroundHostForExtension(extension->id())-> |
72 render_view_host(); | 78 render_view_host(); |
73 } | 79 } |
74 | 80 |
75 void ExecuteCmdAndCheckReply(content::RenderViewHost* host, | 81 void ExecuteCmdAndCheckReply(content::RenderViewHost* host, |
76 const std::string& js_command, | 82 const std::string& js_command, |
(...skipping 19 matching lines...) Expand all Loading... | |
96 } | 102 } |
97 | 103 |
98 static std::string GetDeviceId() { | 104 static std::string GetDeviceId() { |
99 return chrome::StorageInfo::MakeDeviceId( | 105 return chrome::StorageInfo::MakeDeviceId( |
100 chrome::StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, kDeviceId); | 106 chrome::StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, kDeviceId); |
101 } | 107 } |
102 | 108 |
103 protected: | 109 protected: |
104 const std::string device_id_; | 110 const std::string device_id_; |
105 | 111 |
112 chrome::test::TestStorageMonitor* monitor_; | |
113 | |
106 private: | 114 private: |
107 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPrivateEjectApiTest); | 115 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPrivateEjectApiTest); |
108 }; | 116 }; |
109 | 117 |
110 | 118 |
111 /////////////////////////////////////////////////////////////////////////////// | 119 /////////////////////////////////////////////////////////////////////////////// |
112 // TESTS // | 120 // TESTS // |
113 /////////////////////////////////////////////////////////////////////////////// | 121 /////////////////////////////////////////////////////////////////////////////// |
114 | 122 |
115 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateEjectApiTest, EjectTest) { | 123 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateEjectApiTest, EjectTest) { |
116 scoped_ptr<chrome::test::TestStorageMonitor> monitor( | |
117 chrome::test::TestStorageMonitor::CreateForBrowserTests()); | |
118 monitor->Init(); | |
119 monitor->MarkInitialized(); | |
120 | |
121 content::RenderViewHost* host = GetHost(); | 124 content::RenderViewHost* host = GetHost(); |
122 ExecuteCmdAndCheckReply(host, kAddAttachListenerCmd, kAddAttachListenerOk); | 125 ExecuteCmdAndCheckReply(host, kAddAttachListenerCmd, kAddAttachListenerOk); |
123 | 126 |
124 // Attach / detach | 127 // Attach / detach |
125 const std::string expect_attach_msg = | 128 const std::string expect_attach_msg = |
126 base::StringPrintf("%s,%s", kAttachTestOk, kDeviceName); | 129 base::StringPrintf("%s,%s", kAttachTestOk, kDeviceName); |
127 ExtensionTestMessageListener attach_finished_listener(expect_attach_msg, | 130 ExtensionTestMessageListener attach_finished_listener(expect_attach_msg, |
128 false /* no reply */); | 131 false /* no reply */); |
129 Attach(); | 132 Attach(); |
130 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied()); | 133 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied()); |
131 | 134 |
132 ExecuteCmdAndCheckReply(host, kEjectTestCmd, kEjectListenerOk); | 135 ExecuteCmdAndCheckReply(host, kEjectTestCmd, kEjectListenerOk); |
133 EXPECT_EQ(device_id_, monitor->ejected_device()); | 136 EXPECT_EQ(device_id_, monitor_->ejected_device()); |
134 | 137 |
135 Detach(); | 138 Detach(); |
136 } | 139 } |
137 | 140 |
138 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateEjectApiTest, EjectBadDeviceTest) { | 141 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateEjectApiTest, EjectBadDeviceTest) { |
139 scoped_ptr<chrome::test::TestStorageMonitor> monitor( | |
140 chrome::test::TestStorageMonitor::CreateForBrowserTests()); | |
141 monitor->Init(); | |
142 monitor->MarkInitialized(); | |
143 | |
144 ExecuteCmdAndCheckReply(GetHost(), kEjectFailTestCmd, kEjectFailListenerOk); | 142 ExecuteCmdAndCheckReply(GetHost(), kEjectFailTestCmd, kEjectFailListenerOk); |
145 | 143 |
146 EXPECT_EQ("", monitor->ejected_device()); | 144 EXPECT_EQ("", monitor_->ejected_device()); |
147 } | 145 } |
OLD | NEW |