blob: 0122151904fa7c21dcdd4662bd0cc837d73b2a9c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/memory/scoped_ptr.h"
#include "base/run_loop.h"
#include "chrome/browser/extensions/api/instance_id/instance_id_api.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_gcm_app_handler.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/services/gcm/fake_gcm_profile_service.h"
#include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
#include "chrome/browser/services/gcm/instance_id/instance_id_profile_service_factory.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/features/feature_channel.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h"
#include "extensions/test/result_catcher.h"
using extensions::ResultCatcher;
namespace extensions {
namespace {
scoped_ptr<KeyedService> BuildFakeGCMProfileService(
content::BrowserContext* context) {
scoped_ptr<gcm::FakeGCMProfileService> service(
new gcm::FakeGCMProfileService(Profile::FromBrowserContext(context)));
service->SetDriverForTesting(new instance_id::FakeGCMDriverForInstanceID());
return service.Pass();
}
} // namespace
class InstanceIDApiTest : public ExtensionApiTest {
public:
InstanceIDApiTest();
protected:
void SetUpOnMainThread() override;
void SetUpCommandLine(base::CommandLine* command_line) override;
private:
extensions::ScopedCurrentChannel current_channel_;
DISALLOW_COPY_AND_ASSIGN(InstanceIDApiTest);
};
InstanceIDApiTest::InstanceIDApiTest()
: current_channel_(version_info::Channel::DEV) {
}
void InstanceIDApiTest::SetUpOnMainThread() {
gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactory(
browser()->profile(), &BuildFakeGCMProfileService);
ExtensionApiTest::SetUpOnMainThread();
}
void InstanceIDApiTest::SetUpCommandLine(base::CommandLine* command_line) {
ExtensionApiTest::SetUpCommandLine(command_line);
// Makes sure InstanceID is enabled for testing.
command_line->AppendSwitchASCII(
switches::kForceFieldTrials, "InstanceID/Enabled/");
}
IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, GetID) {
ASSERT_TRUE(RunExtensionTest("instance_id/get_id"));
}
IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, GetCreationTime) {
ASSERT_TRUE(RunExtensionTest("instance_id/get_creation_time"));
}
IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, DeleteID) {
ASSERT_TRUE(RunExtensionTest("instance_id/delete_id"));
}
IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, GetToken) {
ASSERT_TRUE(RunExtensionTest("instance_id/get_token"));
}
IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, DeleteToken) {
ASSERT_TRUE(RunExtensionTest("instance_id/delete_token"));
}
IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, Incognito) {
ResultCatcher catcher;
catcher.RestrictToBrowserContext(profile());
ResultCatcher incognito_catcher;
incognito_catcher.RestrictToBrowserContext(
profile()->GetOffTheRecordProfile());
ASSERT_TRUE(RunExtensionTestIncognito("instance_id/incognito"));
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
EXPECT_TRUE(incognito_catcher.GetNextResult()) << incognito_catcher.message();
}
IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, BetaChannel) {
extensions::ScopedCurrentChannel current_channel_override(
version_info::Channel::BETA);
ASSERT_TRUE(RunExtensionTest("instance_id/channel"));
}
IN_PROC_BROWSER_TEST_F(InstanceIDApiTest, StableChannel) {
extensions::ScopedCurrentChannel current_channel_override(
version_info::Channel::STABLE);
ASSERT_TRUE(RunExtensionTest("instance_id/channel"));
}
} // namespace extensions
|