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()), |
| 58 monitor_(NULL) {} |
57 virtual ~MediaGalleriesPrivateEjectApiTest() {} | 59 virtual ~MediaGalleriesPrivateEjectApiTest() {} |
58 | 60 |
59 protected: | 61 protected: |
60 // ExtensionApiTest overrides. | 62 // ExtensionApiTest overrides. |
61 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 63 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
62 ExtensionApiTest::SetUpCommandLine(command_line); | 64 ExtensionApiTest::SetUpCommandLine(command_line); |
63 command_line->AppendSwitchASCII(switches::kWhitelistedExtensionID, | 65 command_line->AppendSwitchASCII(switches::kWhitelistedExtensionID, |
64 kTestExtensionId); | 66 kTestExtensionId); |
65 } | 67 } |
66 | 68 |
| 69 virtual void SetUpOnMainThread() OVERRIDE { |
| 70 monitor_ = chrome::test::TestStorageMonitor::CreateForBrowserTests(); |
| 71 ExtensionApiTest::SetUpOnMainThread(); |
| 72 } |
| 73 |
67 content::RenderViewHost* GetHost() { | 74 content::RenderViewHost* GetHost() { |
68 const extensions::Extension* extension = | 75 const extensions::Extension* extension = |
69 LoadExtension(test_data_dir_.AppendASCII(kTestExtensionPath)); | 76 LoadExtension(test_data_dir_.AppendASCII(kTestExtensionPath)); |
70 return extensions::ExtensionSystem::Get(browser()->profile())-> | 77 return extensions::ExtensionSystem::Get(browser()->profile())-> |
71 process_manager()->GetBackgroundHostForExtension(extension->id())-> | 78 process_manager()->GetBackgroundHostForExtension(extension->id())-> |
72 render_view_host(); | 79 render_view_host(); |
73 } | 80 } |
74 | 81 |
75 void ExecuteCmdAndCheckReply(content::RenderViewHost* host, | 82 void ExecuteCmdAndCheckReply(content::RenderViewHost* host, |
76 const std::string& js_command, | 83 const std::string& js_command, |
(...skipping 19 matching lines...) Expand all Loading... |
96 } | 103 } |
97 | 104 |
98 static std::string GetDeviceId() { | 105 static std::string GetDeviceId() { |
99 return chrome::StorageInfo::MakeDeviceId( | 106 return chrome::StorageInfo::MakeDeviceId( |
100 chrome::StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, kDeviceId); | 107 chrome::StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, kDeviceId); |
101 } | 108 } |
102 | 109 |
103 protected: | 110 protected: |
104 const std::string device_id_; | 111 const std::string device_id_; |
105 | 112 |
| 113 chrome::test::TestStorageMonitor* monitor_; |
| 114 |
106 private: | 115 private: |
107 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPrivateEjectApiTest); | 116 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPrivateEjectApiTest); |
108 }; | 117 }; |
109 | 118 |
110 | 119 |
111 /////////////////////////////////////////////////////////////////////////////// | 120 /////////////////////////////////////////////////////////////////////////////// |
112 // TESTS // | 121 // TESTS // |
113 /////////////////////////////////////////////////////////////////////////////// | 122 /////////////////////////////////////////////////////////////////////////////// |
114 | 123 |
115 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateEjectApiTest, EjectTest) { | 124 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(); | 125 content::RenderViewHost* host = GetHost(); |
122 ExecuteCmdAndCheckReply(host, kAddAttachListenerCmd, kAddAttachListenerOk); | 126 ExecuteCmdAndCheckReply(host, kAddAttachListenerCmd, kAddAttachListenerOk); |
123 | 127 |
124 // Attach / detach | 128 // Attach / detach |
125 const std::string expect_attach_msg = | 129 const std::string expect_attach_msg = |
126 base::StringPrintf("%s,%s", kAttachTestOk, kDeviceName); | 130 base::StringPrintf("%s,%s", kAttachTestOk, kDeviceName); |
127 ExtensionTestMessageListener attach_finished_listener(expect_attach_msg, | 131 ExtensionTestMessageListener attach_finished_listener(expect_attach_msg, |
128 false /* no reply */); | 132 false /* no reply */); |
129 Attach(); | 133 Attach(); |
130 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied()); | 134 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied()); |
131 | 135 |
132 ExecuteCmdAndCheckReply(host, kEjectTestCmd, kEjectListenerOk); | 136 ExecuteCmdAndCheckReply(host, kEjectTestCmd, kEjectListenerOk); |
133 EXPECT_EQ(device_id_, monitor->ejected_device()); | 137 EXPECT_EQ(device_id_, monitor_->ejected_device()); |
134 | 138 |
135 Detach(); | 139 Detach(); |
136 } | 140 } |
137 | 141 |
138 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateEjectApiTest, EjectBadDeviceTest) { | 142 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); | 143 ExecuteCmdAndCheckReply(GetHost(), kEjectFailTestCmd, kEjectFailListenerOk); |
145 | 144 |
146 EXPECT_EQ("", monitor->ejected_device()); | 145 EXPECT_EQ("", monitor_->ejected_device()); |
147 } | 146 } |
OLD | NEW |