Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / api / instance_id / instance_id_apitest.cc
blobbc32d8111bd1a547631cbdd1e9d0ab7319615462
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
3 // found in the LICENSE file.
5 #include "base/memory/scoped_ptr.h"
6 #include "base/run_loop.h"
7 #include "chrome/browser/extensions/api/instance_id/instance_id_api.h"
8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/browser/extensions/extension_gcm_app_handler.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h"
12 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
13 #include "chrome/browser/services/gcm/instance_id/instance_id_profile_service_factory.h"
14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/extensions/features/feature_channel.h"
16 #include "chrome/test/base/ui_test_utils.h"
17 #include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h"
18 #include "extensions/test/result_catcher.h"
20 using extensions::ResultCatcher;
22 namespace extensions {
24 namespace {
26 scoped_ptr<KeyedService> BuildFakeGCMProfileService(
27 content::BrowserContext* context) {
28 scoped_ptr<gcm::FakeGCMProfileService> service(
29 new gcm::FakeGCMProfileService(Profile::FromBrowserContext(context)));
30 service->SetDriverForTesting(new instance_id::FakeGCMDriverForInstanceID());
31 return service.Pass();
34 } // namespace
36 class InstanceIDApiTest : public ExtensionApiTest {
37 public:
38 InstanceIDApiTest();
40 protected:
41 void SetUpOnMainThread() override;
42 void SetUpCommandLine(base::CommandLine* command_line) override;
44 private:
45 extensions::ScopedCurrentChannel current_channel_;
47 DISALLOW_COPY_AND_ASSIGN(InstanceIDApiTest);
50 InstanceIDApiTest::InstanceIDApiTest()
51 : current_channel_(chrome::VersionInfo::CHANNEL_DEV) {
54 void InstanceIDApiTest::SetUpOnMainThread() {
55 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactory(
56 browser()->profile(), &BuildFakeGCMProfileService);
58 ExtensionApiTest::SetUpOnMainThread();
61 void InstanceIDApiTest::SetUpCommandLine(base::CommandLine* command_line) {
62 ExtensionApiTest::SetUpCommandLine(command_line);
64 // Makes sure InstanceID is enabled for testing.
65 command_line->AppendSwitchASCII(
66 switches::kForceFieldTrials, "InstanceID/Enabled/");
69 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, GetID) {
70 ASSERT_TRUE(RunExtensionTest("instance_id/get_id"));
73 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, GetCreationTime) {
74 ASSERT_TRUE(RunExtensionTest("instance_id/get_creation_time"));
77 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, DeleteID) {
78 ASSERT_TRUE(RunExtensionTest("instance_id/delete_id"));
81 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, GetToken) {
82 ASSERT_TRUE(RunExtensionTest("instance_id/get_token"));
85 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, DeleteToken) {
86 ASSERT_TRUE(RunExtensionTest("instance_id/delete_token"));
89 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, Incognito) {
90 ResultCatcher catcher;
91 catcher.RestrictToBrowserContext(profile());
92 ResultCatcher incognito_catcher;
93 incognito_catcher.RestrictToBrowserContext(
94 profile()->GetOffTheRecordProfile());
96 ASSERT_TRUE(RunExtensionTestIncognito("instance_id/incognito"));
98 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
99 EXPECT_TRUE(incognito_catcher.GetNextResult()) << incognito_catcher.message();
102 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, BetaChannel) {
103 extensions::ScopedCurrentChannel current_channel_override(
104 chrome::VersionInfo::CHANNEL_BETA);
105 ASSERT_TRUE(RunExtensionTest("instance_id/channel"));
108 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, StableChannel) {
109 extensions::ScopedCurrentChannel current_channel_override(
110 chrome::VersionInfo::CHANNEL_STABLE);
111 ASSERT_TRUE(RunExtensionTest("instance_id/channel"));
114 } // namespace extensions