• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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 "base/command_line.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "chrome/test/base/test_switches.h"
17 #include "chrome/test/base/ui_test_utils.h"
18 #include "content/public/browser/notification_details.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h"
21 #include "content/public/browser/notification_service.h"
22 #include "content/public/browser/web_contents.h"
23 #include "content/public/test/browser_test_utils.h"
24 #include "extensions/common/extension.h"
25 #include "extensions/common/extension_icon_set.h"
26 #include "extensions/common/manifest_handlers/icons_handler.h"
27 #include "extensions/common/permissions/permission_set.h"
28 #include "extensions/common/permissions/permissions_data.h"
29 
30 namespace extensions {
31 
32 class ExtensionFromWebAppTest
33     : public InProcessBrowserTest, public content::NotificationObserver {
34  protected:
ExtensionFromWebAppTest()35   ExtensionFromWebAppTest() : installed_extension_(NULL) {
36   }
37 
38   std::string expected_extension_id_;
39   const Extension* installed_extension_;
40 
41  private:
42   // content::NotificationObserver
Observe(int type,const content::NotificationSource & source,const content::NotificationDetails & details)43   virtual void Observe(int type,
44                        const content::NotificationSource& source,
45                        const content::NotificationDetails& details) OVERRIDE {
46     if (type == chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED) {
47       const Extension* extension =
48           content::Details<const InstalledExtensionInfo>(details)->extension;
49       if (extension->id() == expected_extension_id_) {
50         installed_extension_ = extension;
51         base::MessageLoopForUI::current()->Quit();
52       }
53     }
54   }
55 };
56 
57 // TODO(samarth): delete along with rest of the NTP4 code.
IN_PROC_BROWSER_TEST_F(ExtensionFromWebAppTest,DISABLED_Basic)58 IN_PROC_BROWSER_TEST_F(ExtensionFromWebAppTest, DISABLED_Basic) {
59 #if defined(OS_WIN) && defined(USE_ASH)
60   // Disable this test in Metro+Ash for now (http://crbug.com/262796).
61   if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
62     return;
63 #endif
64 
65   browser()->profile()->GetExtensionService()->set_show_extensions_prompts(
66       false);
67 
68   content::NotificationRegistrar registrar;
69   registrar.Add(this,
70                 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED,
71                 content::NotificationService::AllSources());
72 
73   expected_extension_id_ = "ffnmbohohhobhkjpfbefbjifapgcmpaa";
74   ui_test_utils::NavigateToURL(
75       browser(),
76       GURL("chrome://newtab"));
77   EXPECT_TRUE(content::ExecuteScript(
78       browser()->tab_strip_model()->GetActiveWebContents(),
79       "chrome.send('generateAppForLink', "
80       "['http://www.example.com', 'Test application', 0])"));
81 
82   if (!installed_extension_)
83     content::RunMessageLoop();
84 
85   EXPECT_TRUE(installed_extension_);
86   EXPECT_TRUE(installed_extension_->is_hosted_app());
87   EXPECT_EQ("Test application", installed_extension_->name());
88   EXPECT_EQ("", installed_extension_->description());
89   EXPECT_EQ(GURL("http://www.example.com/"),
90             AppLaunchInfo::GetLaunchWebURL(installed_extension_));
91   EXPECT_EQ(LAUNCH_CONTAINER_TAB,
92             AppLaunchInfo::GetLaunchContainer(installed_extension_));
93   EXPECT_EQ(0u,
94             installed_extension_->permissions_data()
95                 ->active_permissions()
96                 ->apis()
97                 .size());
98   EXPECT_EQ(0u, IconsInfo::GetIcons(installed_extension_).map().size());
99 }
100 
101 }  // namespace extensions
102