OLD | NEW |
---|---|
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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.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/api/push_messaging/sync_setup_helper.h" | 10 #include "chrome/browser/extensions/api/push_messaging/sync_setup_helper.h" |
11 #include "chrome/browser/extensions/extension_apitest.h" | 11 #include "chrome/browser/extensions/extension_apitest.h" |
12 #include "chrome/browser/extensions/extension_service.h" | |
13 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
17 #include "content/public/browser/render_frame_host.h" | 16 #include "content/public/browser/render_frame_host.h" |
18 #include "extensions/common/extension_set.h" | 17 #include "extensions/browser/extension_registry.h" |
19 #include "extensions/test/result_catcher.h" | 18 #include "extensions/test/result_catcher.h" |
20 #include "net/dns/mock_host_resolver.h" | 19 #include "net/dns/mock_host_resolver.h" |
21 | 20 |
22 namespace { | 21 namespace { |
23 const char kTestExtensionId[] = "mfaehphpebmlbfdiegjnpidmibldjbjk"; | 22 const char kTestExtensionId[] = "mfaehphpebmlbfdiegjnpidmibldjbjk"; |
24 const char kPasswordFileForTest[] = "password-file-for-test"; | 23 const char kPasswordFileForTest[] = "password-file-for-test"; |
25 const char kOverrideUserDataDir[] = "override-user-data-dir"; | 24 const char kOverrideUserDataDir[] = "override-user-data-dir"; |
26 } // namespace | 25 } // namespace |
27 | 26 |
28 namespace extensions { | 27 namespace extensions { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 scoped_ptr<net::ScopedDefaultHostResolverProc> mock_host_resolver_override_; | 125 scoped_ptr<net::ScopedDefaultHostResolverProc> mock_host_resolver_override_; |
127 }; | 126 }; |
128 | 127 |
129 // Test that a push can make a round trip through the servers. | 128 // Test that a push can make a round trip through the servers. |
130 // This test is disabled to keep it from running on trybots since | 129 // This test is disabled to keep it from running on trybots since |
131 // it requires network access, and it is not a good idea to run | 130 // it requires network access, and it is not a good idea to run |
132 // this test as part of a checkin or nightly test. | 131 // this test as part of a checkin or nightly test. |
133 IN_PROC_BROWSER_TEST_F(PushMessagingCanaryTest, MANUAL_ReceivesPush) { | 132 IN_PROC_BROWSER_TEST_F(PushMessagingCanaryTest, MANUAL_ReceivesPush) { |
134 InitializeSync(); | 133 InitializeSync(); |
135 | 134 |
136 const ExtensionSet* installed_extensions = extension_service()->extensions(); | 135 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
137 if (!installed_extensions->Contains(kTestExtensionId)) { | 136 if (!registry->GetExtensionById(kTestExtensionId, |
not at google - send to devlin
2014/11/11 20:20:09
enabled_extensions() thing again (and below).
Reilly Grant (use Gerrit)
2014/11/11 20:55:31
Done.
| |
137 ExtensionRegistry::ENABLED)) { | |
138 const Extension* extension = | 138 const Extension* extension = |
139 LoadExtension(test_data_dir_.AppendASCII("push_messaging_canary")); | 139 LoadExtension(test_data_dir_.AppendASCII("push_messaging_canary")); |
140 ASSERT_TRUE(extension); | 140 ASSERT_TRUE(extension); |
141 } | 141 } |
142 ASSERT_TRUE(installed_extensions->Contains(kTestExtensionId)); | 142 ASSERT_TRUE( |
143 registry->GetExtensionById(kTestExtensionId, ExtensionRegistry::ENABLED)); | |
143 | 144 |
144 ResultCatcher catcher; | 145 ResultCatcher catcher; |
145 catcher.RestrictToBrowserContext(profile()); | 146 catcher.RestrictToBrowserContext(profile()); |
146 | 147 |
147 const Extension* extension = | 148 const Extension* extension = |
148 extension_service()->extensions()->GetByID(kTestExtensionId); | 149 registry->GetExtensionById(kTestExtensionId, ExtensionRegistry::ENABLED); |
149 ASSERT_TRUE(extension); | 150 ASSERT_TRUE(extension); |
150 ui_test_utils::NavigateToURL( | 151 ui_test_utils::NavigateToURL( |
151 browser(), extension->GetResourceURL("push_messaging_canary.html")); | 152 browser(), extension->GetResourceURL("push_messaging_canary.html")); |
152 | 153 |
153 const std::string& client_id = sync_setup_helper()->client_id(); | 154 const std::string& client_id = sync_setup_helper()->client_id(); |
154 const std::string& client_secret = sync_setup_helper()->client_secret(); | 155 const std::string& client_secret = sync_setup_helper()->client_secret(); |
155 const std::string& refresh_token = sync_setup_helper()->refresh_token(); | 156 const std::string& refresh_token = sync_setup_helper()->refresh_token(); |
156 | 157 |
157 const base::string16& script_string = base::UTF8ToUTF16(base::StringPrintf( | 158 const base::string16& script_string = base::UTF8ToUTF16(base::StringPrintf( |
158 "startTestWithCredentials('%s', '%s', '%s');", | 159 "startTestWithCredentials('%s', '%s', '%s');", |
159 client_id.c_str(), client_secret.c_str(), refresh_token.c_str())); | 160 client_id.c_str(), client_secret.c_str(), refresh_token.c_str())); |
160 | 161 |
161 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()-> | 162 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()-> |
162 ExecuteJavaScript(script_string); | 163 ExecuteJavaScript(script_string); |
163 | 164 |
164 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 165 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
165 } | 166 } |
166 | 167 |
167 } // namespace extensions | 168 } // namespace extensions |
OLD | NEW |