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) {} | |
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 |
(...skipping 29 matching lines...) Expand all Loading... | |
96 } | 97 } |
97 | 98 |
98 static std::string GetDeviceId() { | 99 static std::string GetDeviceId() { |
99 return chrome::StorageInfo::MakeDeviceId( | 100 return chrome::StorageInfo::MakeDeviceId( |
100 chrome::StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, kDeviceId); | 101 chrome::StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, kDeviceId); |
101 } | 102 } |
102 | 103 |
103 protected: | 104 protected: |
104 const std::string device_id_; | 105 const std::string device_id_; |
105 | 106 |
107 // Weak ptr to the storage monitor owned by the browser process. | |
108 chrome::test::TestStorageMonitor* monitor_; | |
109 | |
106 private: | 110 private: |
107 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPrivateEjectApiTest); | 111 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPrivateEjectApiTest); |
108 }; | 112 }; |
109 | 113 |
110 | 114 |
111 /////////////////////////////////////////////////////////////////////////////// | 115 /////////////////////////////////////////////////////////////////////////////// |
112 // TESTS // | 116 // TESTS // |
113 /////////////////////////////////////////////////////////////////////////////// | 117 /////////////////////////////////////////////////////////////////////////////// |
114 | 118 |
115 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateEjectApiTest, EjectTest) { | 119 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateEjectApiTest, EjectTest) { |
116 scoped_ptr<chrome::test::TestStorageMonitor> monitor( | 120 monitor_ = chrome::test::TestStorageMonitor::CreateForBrowserTests(); |
Lei Zhang
2013/07/02 23:16:57
Just override InProcesBrowserTest::SetUpOnMainThre
Greg Billock
2013/07/03 17:49:17
That's what I initially did. There's some kind of
Lei Zhang
2013/07/03 23:25:10
I tried it and it seems to work for me. SetUpOnMai
Greg Billock
2013/07/08 18:50:07
Yeah. I have no idea what I was doing wrong. Tried
| |
117 chrome::test::TestStorageMonitor::CreateForBrowserTests()); | |
118 monitor->Init(); | |
119 monitor->MarkInitialized(); | |
120 | |
121 content::RenderViewHost* host = GetHost(); | 121 content::RenderViewHost* host = GetHost(); |
122 ExecuteCmdAndCheckReply(host, kAddAttachListenerCmd, kAddAttachListenerOk); | 122 ExecuteCmdAndCheckReply(host, kAddAttachListenerCmd, kAddAttachListenerOk); |
123 | 123 |
124 // Attach / detach | 124 // Attach / detach |
125 const std::string expect_attach_msg = | 125 const std::string expect_attach_msg = |
126 base::StringPrintf("%s,%s", kAttachTestOk, kDeviceName); | 126 base::StringPrintf("%s,%s", kAttachTestOk, kDeviceName); |
127 ExtensionTestMessageListener attach_finished_listener(expect_attach_msg, | 127 ExtensionTestMessageListener attach_finished_listener(expect_attach_msg, |
128 false /* no reply */); | 128 false /* no reply */); |
129 Attach(); | 129 Attach(); |
130 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied()); | 130 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied()); |
131 | 131 |
132 ExecuteCmdAndCheckReply(host, kEjectTestCmd, kEjectListenerOk); | 132 ExecuteCmdAndCheckReply(host, kEjectTestCmd, kEjectListenerOk); |
133 EXPECT_EQ(device_id_, monitor->ejected_device()); | 133 EXPECT_EQ(device_id_, monitor_->ejected_device()); |
134 | 134 |
135 Detach(); | 135 Detach(); |
136 } | 136 } |
137 | 137 |
138 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateEjectApiTest, EjectBadDeviceTest) { | 138 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateEjectApiTest, EjectBadDeviceTest) { |
139 scoped_ptr<chrome::test::TestStorageMonitor> monitor( | 139 monitor_ = chrome::test::TestStorageMonitor::CreateForBrowserTests(); |
140 chrome::test::TestStorageMonitor::CreateForBrowserTests()); | |
141 monitor->Init(); | |
142 monitor->MarkInitialized(); | |
143 | |
144 ExecuteCmdAndCheckReply(GetHost(), kEjectFailTestCmd, kEjectFailListenerOk); | 140 ExecuteCmdAndCheckReply(GetHost(), kEjectFailTestCmd, kEjectFailListenerOk); |
145 | 141 |
146 EXPECT_EQ("", monitor->ejected_device()); | 142 EXPECT_EQ("", monitor_->ejected_device()); |
147 } | 143 } |
OLD | NEW |