1 // Copyright (c) 2011 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 <string>
6
7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "chrome/common/extensions/extension.h"
12 #include "chrome/test/in_process_browser_test.h"
13 #include "chrome/test/ui_test_utils.h"
14 #include "content/common/notification_details.h"
15 #include "content/common/notification_observer.h"
16 #include "content/common/notification_registrar.h"
17 #include "content/common/notification_type.h"
18
19 class ExtensionFromWebAppTest
20 : public InProcessBrowserTest, public NotificationObserver {
21 protected:
ExtensionFromWebAppTest()22 ExtensionFromWebAppTest() : installed_extension_(NULL) {
23 }
24
25 std::string expected_extension_id_;
26 const Extension* installed_extension_;
27
28 private:
29 // InProcessBrowserTest
SetUpCommandLine(CommandLine * command_line)30 virtual void SetUpCommandLine(CommandLine* command_line) {
31 command_line->AppendSwitch(switches::kEnableCrxlessWebApps);
32 }
33
34 // NotificationObserver
Observe(NotificationType type,const NotificationSource & source,const NotificationDetails & details)35 virtual void Observe(NotificationType type,
36 const NotificationSource& source,
37 const NotificationDetails& details) {
38 if (type == NotificationType::EXTENSION_INSTALLED) {
39 const Extension* extension = Details<const Extension>(details).ptr();
40 if (extension->id() == expected_extension_id_) {
41 installed_extension_ = extension;
42 MessageLoopForUI::current()->Quit();
43 }
44 }
45 }
46 };
47
IN_PROC_BROWSER_TEST_F(ExtensionFromWebAppTest,Basic)48 IN_PROC_BROWSER_TEST_F(ExtensionFromWebAppTest, Basic) {
49 ASSERT_TRUE(test_server()->Start());
50 browser()->profile()->GetExtensionService()->set_show_extensions_prompts(
51 false);
52
53 NotificationRegistrar registrar;
54 registrar.Add(this, NotificationType::EXTENSION_INSTALLED,
55 NotificationService::AllSources());
56
57 expected_extension_id_ = "fnpgoaochgbdfjndakichfafiocjjpmm";
58 ui_test_utils::NavigateToURL(
59 browser(),
60 test_server()->GetURL(
61 "files/extensions/convert_web_app/application.html"));
62
63 if (!installed_extension_)
64 ui_test_utils::RunMessageLoop();
65
66 EXPECT_TRUE(installed_extension_);
67 EXPECT_TRUE(installed_extension_->is_hosted_app());
68 EXPECT_EQ("Test application", installed_extension_->name());
69 EXPECT_EQ("the description is", installed_extension_->description());
70 EXPECT_EQ(extension_misc::LAUNCH_PANEL,
71 installed_extension_->launch_container());
72
73 ASSERT_EQ(2u, installed_extension_->api_permissions().size());
74 EXPECT_TRUE(installed_extension_->api_permissions().find("geolocation") !=
75 installed_extension_->api_permissions().end());
76 EXPECT_TRUE(installed_extension_->api_permissions().find("notifications") !=
77 installed_extension_->api_permissions().end());
78
79 ASSERT_EQ(3u, installed_extension_->icons().map().size());
80 EXPECT_EQ("icons/16.png", installed_extension_->icons().Get(
81 16, ExtensionIconSet::MATCH_EXACTLY));
82 EXPECT_EQ("icons/48.png", installed_extension_->icons().Get(
83 48, ExtensionIconSet::MATCH_EXACTLY));
84 EXPECT_EQ("icons/128.png", installed_extension_->icons().Get(
85 128, ExtensionIconSet::MATCH_EXACTLY));
86 }
87