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

Side by Side Diff: chrome/browser/extensions/api/instance_id/instance_id_apitest.cc

Issue 1139633005: Make chrome.instanceID only available on dev and canary. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing new files Created 5 years, 7 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/run_loop.h" 5 #include "base/run_loop.h"
6 #include "chrome/browser/extensions/api/instance_id/instance_id_api.h" 6 #include "chrome/browser/extensions/api/instance_id/instance_id_api.h"
7 #include "chrome/browser/extensions/extension_apitest.h" 7 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "chrome/browser/extensions/extension_gcm_app_handler.h" 8 #include "chrome/browser/extensions/extension_gcm_app_handler.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" 10 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h"
11 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" 11 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
12 #include "chrome/browser/services/gcm/instance_id/instance_id_profile_service_fa ctory.h" 12 #include "chrome/browser/services/gcm/instance_id/instance_id_profile_service_fa ctory.h"
13 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/extensions/features/feature_channel.h"
14 #include "chrome/test/base/ui_test_utils.h" 14 #include "chrome/test/base/ui_test_utils.h"
15 #include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h" 15 #include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h"
16 #include "extensions/test/result_catcher.h" 16 #include "extensions/test/result_catcher.h"
17 17
18 using extensions::ResultCatcher; 18 using extensions::ResultCatcher;
19 19
20 namespace extensions { 20 namespace extensions {
21 21
22 namespace { 22 namespace {
23 23
24 KeyedService* BuildFakeGCMProfileService(content::BrowserContext* context) { 24 KeyedService* BuildFakeGCMProfileService(content::BrowserContext* context) {
25 gcm::FakeGCMProfileService* service = 25 gcm::FakeGCMProfileService* service =
26 new gcm::FakeGCMProfileService(Profile::FromBrowserContext(context)); 26 new gcm::FakeGCMProfileService(Profile::FromBrowserContext(context));
27 service->SetDriverForTesting(new instance_id::FakeGCMDriverForInstanceID()); 27 service->SetDriverForTesting(new instance_id::FakeGCMDriverForInstanceID());
28 return service; 28 return service;
29 } 29 }
30 30
31 } // namespace 31 } // namespace
32 32
33 class InstanceIDApiTest : public ExtensionApiTest { 33 class InstanceIDApiTest : public ExtensionApiTest {
34 public: 34 public:
35 InstanceIDApiTest() {} 35 InstanceIDApiTest() {}
36 36
37 protected: 37 protected:
38 void SetUpOnMainThread() override; 38 void SetUpOnMainThread() override;
39 void SetUpCommandLine(base::CommandLine* command_line) override;
40 39
41 private: 40 private:
42 DISALLOW_COPY_AND_ASSIGN(InstanceIDApiTest); 41 DISALLOW_COPY_AND_ASSIGN(InstanceIDApiTest);
43 }; 42 };
44 43
45 void InstanceIDApiTest::SetUpOnMainThread() { 44 void InstanceIDApiTest::SetUpOnMainThread() {
46 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactory( 45 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactory(
47 browser()->profile(), &BuildFakeGCMProfileService); 46 browser()->profile(), &BuildFakeGCMProfileService);
48 47
49 ExtensionApiTest::SetUpOnMainThread(); 48 ExtensionApiTest::SetUpOnMainThread();
50 } 49 }
51 50
52 void InstanceIDApiTest::SetUpCommandLine(base::CommandLine* command_line) {
53 ExtensionApiTest::SetUpCommandLine(command_line);
54
55 // Makes sure InstanceID is enabled for testing.
56 command_line->AppendSwitchASCII(
57 switches::kForceFieldTrials, "InstanceID/Enabled/");
58 }
59
60 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, GetID) { 51 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, GetID) {
52 extensions::ScopedCurrentChannel current_channel(
53 chrome::VersionInfo::CHANNEL_CANARY);
not at google - send to devlin 2015/05/15 23:07:26 use DEV, and have the ScopedCurrentChannel be a me
jianli 2015/05/15 23:11:37 The following tests check against DEV. I just want
61 ASSERT_TRUE(RunExtensionTest("instance_id/get_id")); 54 ASSERT_TRUE(RunExtensionTest("instance_id/get_id"));
62 } 55 }
63 56
64 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, GetCreationTime) { 57 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, GetCreationTime) {
58 extensions::ScopedCurrentChannel current_channel(
59 chrome::VersionInfo::CHANNEL_DEV);
65 ASSERT_TRUE(RunExtensionTest("instance_id/get_creation_time")); 60 ASSERT_TRUE(RunExtensionTest("instance_id/get_creation_time"));
66 } 61 }
67 62
68 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, DeleteID) { 63 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, DeleteID) {
64 extensions::ScopedCurrentChannel current_channel(
65 chrome::VersionInfo::CHANNEL_DEV);
69 ASSERT_TRUE(RunExtensionTest("instance_id/delete_id")); 66 ASSERT_TRUE(RunExtensionTest("instance_id/delete_id"));
70 } 67 }
71 68
72 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, GetToken) { 69 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, GetToken) {
70 extensions::ScopedCurrentChannel current_channel(
71 chrome::VersionInfo::CHANNEL_DEV);
73 ASSERT_TRUE(RunExtensionTest("instance_id/get_token")); 72 ASSERT_TRUE(RunExtensionTest("instance_id/get_token"));
74 } 73 }
75 74
76 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, DeleteToken) { 75 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, DeleteToken) {
76 extensions::ScopedCurrentChannel current_channel(
77 chrome::VersionInfo::CHANNEL_DEV);
77 ASSERT_TRUE(RunExtensionTest("instance_id/delete_token")); 78 ASSERT_TRUE(RunExtensionTest("instance_id/delete_token"));
78 } 79 }
79 80
80 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, Incognito) { 81 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, Incognito) {
82 extensions::ScopedCurrentChannel current_channel(
83 chrome::VersionInfo::CHANNEL_DEV);
84
81 ResultCatcher catcher; 85 ResultCatcher catcher;
82 catcher.RestrictToBrowserContext(profile()); 86 catcher.RestrictToBrowserContext(profile());
83 ResultCatcher incognito_catcher; 87 ResultCatcher incognito_catcher;
84 incognito_catcher.RestrictToBrowserContext( 88 incognito_catcher.RestrictToBrowserContext(
85 profile()->GetOffTheRecordProfile()); 89 profile()->GetOffTheRecordProfile());
86 90
87 ASSERT_TRUE(RunExtensionTestIncognito("instance_id/incognito")); 91 ASSERT_TRUE(RunExtensionTestIncognito("instance_id/incognito"));
88 92
89 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 93 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
90 EXPECT_TRUE(incognito_catcher.GetNextResult()) << incognito_catcher.message(); 94 EXPECT_TRUE(incognito_catcher.GetNextResult()) << incognito_catcher.message();
91 } 95 }
92 96
97 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, BetaChannel) {
98 extensions::ScopedCurrentChannel current_channel(
99 chrome::VersionInfo::CHANNEL_BETA);
100 ASSERT_TRUE(RunExtensionTest("instance_id/channel"));
101 }
102
103 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, StableChannel) {
104 extensions::ScopedCurrentChannel current_channel(
105 chrome::VersionInfo::CHANNEL_STABLE);
106 ASSERT_TRUE(RunExtensionTest("instance_id/channel"));
107 }
108
93 } // namespace extensions 109 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698