OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/ui/app_list/drive/drive_app_converter.h" | 5 #include "chrome/browser/apps/drive/drive_app_converter.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/version.h" | 12 #include "base/version.h" |
13 #include "chrome/browser/extensions/extension_browsertest.h" | 13 #include "chrome/browser/extensions/extension_browsertest.h" |
14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
16 #include "chrome/common/extensions/extension_constants.h" | 16 #include "chrome/common/extensions/extension_constants.h" |
17 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 17 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 18 #include "chrome/common/extensions/sync_helper.h" |
18 #include "content/public/test/test_utils.h" | 19 #include "content/public/test/test_utils.h" |
19 #include "extensions/browser/extension_system.h" | 20 #include "extensions/browser/extension_system.h" |
20 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
21 #include "extensions/common/manifest_handlers/icons_handler.h" | 22 #include "extensions/common/manifest_handlers/icons_handler.h" |
22 #include "extensions/common/permissions/permission_set.h" | 23 #include "extensions/common/permissions/permission_set.h" |
23 #include "net/test/embedded_test_server/embedded_test_server.h" | 24 #include "net/test/embedded_test_server/embedded_test_server.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 | 26 |
| 27 namespace extensions { |
| 28 |
26 namespace { | 29 namespace { |
27 | 30 |
28 const char kAppName[] = "Test drive app"; | 31 const char kAppName[] = "Test drive app"; |
29 const char kAppUrl[] = "http://foobar.com/drive_app"; | 32 const char kAppUrl[] = "http://foobar.com/drive_app"; |
30 | 33 |
31 } // namespace | 34 } // namespace |
32 | 35 |
33 class DriveAppConverterTest : public ExtensionBrowserTest { | 36 class DriveAppConverterTest : public ExtensionBrowserTest { |
34 public: | 37 public: |
35 DriveAppConverterTest() {} | 38 DriveAppConverterTest() {} |
36 virtual ~DriveAppConverterTest() {} | 39 virtual ~DriveAppConverterTest() {} |
37 | 40 |
38 // ExtensionBrowserTest: | 41 // ExtensionBrowserTest: |
39 virtual void SetUpOnMainThread() OVERRIDE { | 42 virtual void SetUpOnMainThread() OVERRIDE { |
40 ExtensionBrowserTest::SetUpOnMainThread(); | 43 ExtensionBrowserTest::SetUpOnMainThread(); |
41 | 44 |
42 base::FilePath test_data_dir; | 45 base::FilePath test_data_dir; |
43 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); | 46 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 98 |
96 scoped_ptr<DriveAppConverter> converter_; | 99 scoped_ptr<DriveAppConverter> converter_; |
97 scoped_refptr<content::MessageLoopRunner> runner_; | 100 scoped_refptr<content::MessageLoopRunner> runner_; |
98 | 101 |
99 DISALLOW_COPY_AND_ASSIGN(DriveAppConverterTest); | 102 DISALLOW_COPY_AND_ASSIGN(DriveAppConverterTest); |
100 }; | 103 }; |
101 | 104 |
102 IN_PROC_BROWSER_TEST_F(DriveAppConverterTest, GoodApp) { | 105 IN_PROC_BROWSER_TEST_F(DriveAppConverterTest, GoodApp) { |
103 InstallAndWaitFinish(GetTestDriveApp()); | 106 InstallAndWaitFinish(GetTestDriveApp()); |
104 | 107 |
105 const extensions::Extension* app = converter()->app(); | 108 const Extension* app = converter()->app(); |
106 ASSERT_TRUE(app != NULL); | 109 ASSERT_TRUE(app != NULL); |
107 EXPECT_EQ(kAppName, app->name()); | 110 EXPECT_EQ(kAppName, app->name()); |
108 EXPECT_TRUE(app->is_hosted_app()); | 111 EXPECT_TRUE(app->is_hosted_app()); |
109 EXPECT_TRUE(app->from_bookmark()); | 112 EXPECT_TRUE(app->from_bookmark()); |
110 EXPECT_EQ(GURL(kAppUrl), extensions::AppLaunchInfo::GetLaunchWebURL(app)); | 113 EXPECT_EQ(GURL(kAppUrl), AppLaunchInfo::GetLaunchWebURL(app)); |
111 EXPECT_EQ(extensions::LAUNCH_CONTAINER_TAB, | 114 EXPECT_EQ(LAUNCH_CONTAINER_TAB, AppLaunchInfo::GetLaunchContainer(app)); |
112 extensions::AppLaunchInfo::GetLaunchContainer(app)); | |
113 EXPECT_EQ(0u, app->GetActivePermissions()->apis().size()); | 115 EXPECT_EQ(0u, app->GetActivePermissions()->apis().size()); |
114 EXPECT_EQ(1u, extensions::IconsInfo::GetIcons(app).map().size()); | 116 EXPECT_EQ(1u, IconsInfo::GetIcons(app).map().size()); |
115 | 117 |
116 const extensions::Extension* installed = | 118 const Extension* installed = ExtensionSystem::Get(profile()) |
117 extensions::ExtensionSystem::Get(profile()) | 119 ->extension_service() |
118 ->extension_service() | 120 ->GetInstalledExtension(app->id()); |
119 ->GetInstalledExtension(app->id()); | |
120 EXPECT_EQ(app, installed); | 121 EXPECT_EQ(app, installed); |
| 122 EXPECT_FALSE(sync_helper::IsSyncable(app)); |
121 } | 123 } |
122 | 124 |
123 IN_PROC_BROWSER_TEST_F(DriveAppConverterTest, BadApp) { | 125 IN_PROC_BROWSER_TEST_F(DriveAppConverterTest, BadApp) { |
124 drive::DriveAppInfo no_name = GetTestDriveApp(); | 126 drive::DriveAppInfo no_name = GetTestDriveApp(); |
125 no_name.app_name.clear(); | 127 no_name.app_name.clear(); |
126 InstallAndWaitFinish(no_name); | 128 InstallAndWaitFinish(no_name); |
127 EXPECT_TRUE(converter()->app() == NULL); | 129 EXPECT_TRUE(converter()->app() == NULL); |
128 | 130 |
129 drive::DriveAppInfo no_url = GetTestDriveApp(); | 131 drive::DriveAppInfo no_url = GetTestDriveApp(); |
130 no_url.create_url = GURL(); | 132 no_url.create_url = GURL(); |
131 InstallAndWaitFinish(no_url); | 133 InstallAndWaitFinish(no_url); |
132 EXPECT_TRUE(converter()->app() == NULL); | 134 EXPECT_TRUE(converter()->app() == NULL); |
133 } | 135 } |
134 | 136 |
135 IN_PROC_BROWSER_TEST_F(DriveAppConverterTest, InstallTwice) { | 137 IN_PROC_BROWSER_TEST_F(DriveAppConverterTest, InstallTwice) { |
136 InstallAndWaitFinish(GetTestDriveApp()); | 138 InstallAndWaitFinish(GetTestDriveApp()); |
137 const extensions::Extension* first_install = converter()->app(); | 139 const Extension* first_install = converter()->app(); |
138 ASSERT_TRUE(first_install != NULL); | 140 ASSERT_TRUE(first_install != NULL); |
139 const std::string first_install_id = first_install->id(); | 141 const std::string first_install_id = first_install->id(); |
140 const base::Version first_install_version(first_install->VersionString()); | 142 const base::Version first_install_version(first_install->VersionString()); |
141 ASSERT_TRUE(first_install_version.IsValid()); | 143 ASSERT_TRUE(first_install_version.IsValid()); |
142 | 144 |
143 InstallAndWaitFinish(GetTestDriveApp()); | 145 InstallAndWaitFinish(GetTestDriveApp()); |
144 const extensions::Extension* second_install = converter()->app(); | 146 const Extension* second_install = converter()->app(); |
145 ASSERT_TRUE(second_install != NULL); | 147 ASSERT_TRUE(second_install != NULL); |
146 | 148 |
147 // Two different app instances. | 149 // Two different app instances. |
148 ASSERT_NE(first_install, second_install); | 150 ASSERT_NE(first_install, second_install); |
149 EXPECT_EQ(first_install_id, second_install->id()); | 151 EXPECT_EQ(first_install_id, second_install->id()); |
150 EXPECT_GE(second_install->version()->CompareTo(first_install_version), 0); | 152 EXPECT_GE(second_install->version()->CompareTo(first_install_version), 0); |
151 } | 153 } |
| 154 |
| 155 } // namespace extensions |
OLD | NEW |