Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / extensions / api / instance_id / instance_id_apitest.cc
blob367d7a01a2e0d276b82a51863af99c05203462bd
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/test/base/ui_test_utils.h"
16 #include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h"
17 #include "components/version_info/version_info.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 DISALLOW_COPY_AND_ASSIGN(InstanceIDApiTest);
48 InstanceIDApiTest::InstanceIDApiTest() {
51 void InstanceIDApiTest::SetUpOnMainThread() {
52 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactory(
53 browser()->profile(), &BuildFakeGCMProfileService);
55 ExtensionApiTest::SetUpOnMainThread();
58 void InstanceIDApiTest::SetUpCommandLine(base::CommandLine* command_line) {
59 ExtensionApiTest::SetUpCommandLine(command_line);
61 // Makes sure InstanceID is enabled for testing.
62 command_line->AppendSwitchASCII(
63 switches::kForceFieldTrials, "InstanceID/Enabled/");
66 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, GetID) {
67 ASSERT_TRUE(RunExtensionTest("instance_id/get_id"));
70 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, GetCreationTime) {
71 ASSERT_TRUE(RunExtensionTest("instance_id/get_creation_time"));
74 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, DeleteID) {
75 ASSERT_TRUE(RunExtensionTest("instance_id/delete_id"));
78 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, GetToken) {
79 ASSERT_TRUE(RunExtensionTest("instance_id/get_token"));
82 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, DeleteToken) {
83 ASSERT_TRUE(RunExtensionTest("instance_id/delete_token"));
86 IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, Incognito) {
87 ResultCatcher catcher;
88 catcher.RestrictToBrowserContext(profile());
89 ResultCatcher incognito_catcher;
90 incognito_catcher.RestrictToBrowserContext(
91 profile()->GetOffTheRecordProfile());
93 ASSERT_TRUE(RunExtensionTestIncognito("instance_id/incognito"));
95 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
96 EXPECT_TRUE(incognito_catcher.GetNextResult()) << incognito_catcher.message();
99 } // namespace extensions