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

Side by Side Diff: chrome/browser/ui/app_list/drive/drive_app_converter_browsertest.cc

Issue 308003005: app_list: Drive app integration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: crx_installer changes Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/app_list/drive/drive_app_converter.h"
6
7 #include <utility>
8
9 #include "base/bind.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/path_service.h"
12 #include "base/version.h"
13 #include "chrome/browser/extensions/extension_browsertest.h"
14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/common/chrome_paths.h"
16 #include "chrome/common/extensions/extension_constants.h"
17 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
18 #include "content/public/test/test_utils.h"
19 #include "extensions/browser/extension_system.h"
20 #include "extensions/common/extension.h"
21 #include "extensions/common/manifest_handlers/icons_handler.h"
22 #include "extensions/common/permissions/permission_set.h"
23 #include "net/test/embedded_test_server/embedded_test_server.h"
24 #include "testing/gtest/include/gtest/gtest.h"
25
26 namespace {
27
28 const char kAppName[] = "Test drive app";
29 const char kAppUrl[] = "http://foobar.com/drive_app";
30
31 } // namespace
32
33 class DriveAppConverterTest : public ExtensionBrowserTest {
34 public:
35 DriveAppConverterTest() {}
36 virtual ~DriveAppConverterTest() {}
37
38 // ExtensionBrowserTest:
39 virtual void SetUpOnMainThread() OVERRIDE {
40 ExtensionBrowserTest::SetUpOnMainThread();
41
42 base::FilePath test_data_dir;
43 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
44 embedded_test_server()->ServeFilesFromDirectory(test_data_dir);
45 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
46 }
47
48 void InstallAndWaitFinish(const drive::DriveAppInfo& drive_app) {
49 runner_ = new content::MessageLoopRunner;
50
51 converter_.reset(new DriveAppConverter(
52 profile(),
53 drive_app,
54 base::Bind(&DriveAppConverterTest::ConverterFinished,
55 base::Unretained(this))));
56 converter_->Start();
57
58 runner_->Run();
59 }
60
61 GURL GetTestUrl(const std::string& path) {
62 return embedded_test_server()->base_url().Resolve(path);
63 }
64
65 drive::DriveAppInfo GetTestDriveApp() {
66 // Define four icons. icon1.png is 16x16 and good to use. icon2.png is
67 // 16x16 but claims to be 32x32 and should be dropped. icon3.png is 66x66
68 // and not a valid extension icon size and should be dropped too. The forth
69 // one is icon2.png with 16x16 but should be ignored because 16x16 already
70 // has icon1.png as its resource.
71 drive::DriveAppInfo::IconList app_icons;
72 app_icons.push_back(std::make_pair(16, GetTestUrl("extensions/icon1.png")));
73 app_icons.push_back(std::make_pair(32, GetTestUrl("extensions/icon2.png")));
74 app_icons.push_back(std::make_pair(66, GetTestUrl("extensions/icon3.png")));
75 app_icons.push_back(std::make_pair(16, GetTestUrl("extensions/icon2.png")));
76
77 drive::DriveAppInfo::IconList document_icons;
78
79 return drive::DriveAppInfo("fake_drive_app_id",
80 "fake_product_id",
81 app_icons,
82 document_icons,
83 kAppName,
84 GURL(kAppUrl),
85 true);
86 }
87
88 const DriveAppConverter* converter() const { return converter_.get(); }
89
90 private:
91 void ConverterFinished(const DriveAppConverter* converter, bool success) {
92 if (runner_)
93 runner_->Quit();
94 }
95
96 scoped_ptr<DriveAppConverter> converter_;
97 scoped_refptr<content::MessageLoopRunner> runner_;
98
99 DISALLOW_COPY_AND_ASSIGN(DriveAppConverterTest);
100 };
101
102 IN_PROC_BROWSER_TEST_F(DriveAppConverterTest, GoodApp) {
103 InstallAndWaitFinish(GetTestDriveApp());
104
105 const extensions::Extension* app = converter()->app();
106 ASSERT_TRUE(app != NULL);
107 EXPECT_EQ(kAppName, app->name());
108 EXPECT_TRUE(app->is_hosted_app());
109 EXPECT_TRUE(app->from_bookmark());
110 EXPECT_EQ(GURL(kAppUrl), extensions::AppLaunchInfo::GetLaunchWebURL(app));
111 EXPECT_EQ(extensions::LAUNCH_CONTAINER_TAB,
112 extensions::AppLaunchInfo::GetLaunchContainer(app));
113 EXPECT_EQ(0u, app->GetActivePermissions()->apis().size());
114 EXPECT_EQ(1u, extensions::IconsInfo::GetIcons(app).map().size());
115
116 const extensions::Extension* installed =
117 extensions::ExtensionSystem::Get(profile())
118 ->extension_service()
119 ->GetInstalledExtension(app->id());
120 EXPECT_EQ(app, installed);
121 }
122
123 IN_PROC_BROWSER_TEST_F(DriveAppConverterTest, BadApp) {
124 drive::DriveAppInfo no_name = GetTestDriveApp();
125 no_name.app_name.clear();
126 InstallAndWaitFinish(no_name);
127 EXPECT_TRUE(converter()->app() == NULL);
128
129 drive::DriveAppInfo no_url = GetTestDriveApp();
130 no_url.create_url = GURL();
131 InstallAndWaitFinish(no_url);
132 EXPECT_TRUE(converter()->app() == NULL);
133 }
134
135 IN_PROC_BROWSER_TEST_F(DriveAppConverterTest, InstallTwice) {
136 InstallAndWaitFinish(GetTestDriveApp());
137 const extensions::Extension* first_install = converter()->app();
138 ASSERT_TRUE(first_install != NULL);
139 const std::string first_install_id = first_install->id();
140 const base::Version first_install_version(first_install->VersionString());
141 ASSERT_TRUE(first_install_version.IsValid());
142
143 InstallAndWaitFinish(GetTestDriveApp());
144 const extensions::Extension* second_install = converter()->app();
145 ASSERT_TRUE(second_install != NULL);
146
147 // Two different app instances.
148 ASSERT_NE(first_install, second_install);
149 EXPECT_EQ(first_install_id, second_install->id());
150 EXPECT_GE(second_install->version()->CompareTo(first_install_version), 0);
151 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698