Home | History | Annotate | Download | only in web_applications
      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 "chrome/browser/web_applications/web_app.h"
      6 
      7 #include "base/files/file_path.h"
      8 #include "base/strings/string_util.h"
      9 #include "base/strings/utf_string_conversions.h"
     10 #include "chrome/browser/extensions/tab_helper.h"
     11 #include "chrome/browser/favicon/favicon_tab_helper.h"
     12 #include "chrome/browser/ui/web_applications/web_app_ui.h"
     13 #include "chrome/common/extensions/extension_messages.h"
     14 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
     15 #include "content/public/test/test_renderer_host.h"
     16 #include "testing/gtest/include/gtest/gtest.h"
     17 
     18 using content::RenderViewHostTester;
     19 
     20 class WebApplicationTest : public ChromeRenderViewHostTestHarness {
     21  protected:
     22   virtual void SetUp() OVERRIDE {
     23     ChromeRenderViewHostTestHarness::SetUp();
     24     extensions::TabHelper::CreateForWebContents(web_contents());
     25     FaviconTabHelper::CreateForWebContents(web_contents());
     26   }
     27 };
     28 
     29 #if defined(OS_MACOSX)
     30 #define MAYBE_GetShortcutInfoForTab DISABLED_GetShortcutInfoForTab
     31 #else
     32 #define MAYBE_GetShortcutInfoForTab GetShortcutInfoForTab
     33 #endif
     34 TEST_F(WebApplicationTest, MAYBE_GetShortcutInfoForTab) {
     35   const string16 title = ASCIIToUTF16("TEST_TITLE");
     36   const string16 description = ASCIIToUTF16("TEST_DESCRIPTION");
     37   const GURL url("http://www.foo.com/bar");
     38   WebApplicationInfo web_app_info;
     39   web_app_info.title = title;
     40   web_app_info.description = description;
     41   web_app_info.app_url = url;
     42 
     43   RenderViewHostTester::TestOnMessageReceived(
     44       rvh(),
     45       ExtensionHostMsg_DidGetApplicationInfo(0, 0, web_app_info));
     46   ShellIntegration::ShortcutInfo info;
     47   web_app::GetShortcutInfoForTab(web_contents(), &info);
     48 
     49   EXPECT_EQ(title, info.title);
     50   EXPECT_EQ(description, info.description);
     51   EXPECT_EQ(url, info.url);
     52 }
     53 
     54 TEST_F(WebApplicationTest, AppDirWithId) {
     55   base::FilePath profile_path(FILE_PATH_LITERAL("profile"));
     56   base::FilePath result(
     57       web_app::GetWebAppDataDirectory(profile_path, "123", GURL()));
     58   base::FilePath expected = profile_path.AppendASCII("Web Applications")
     59                                   .AppendASCII("_crx_123");
     60   EXPECT_EQ(expected, result);
     61 }
     62 
     63 TEST_F(WebApplicationTest, AppDirWithUrl) {
     64   base::FilePath profile_path(FILE_PATH_LITERAL("profile"));
     65   base::FilePath result(web_app::GetWebAppDataDirectory(
     66       profile_path, std::string(), GURL("http://example.com")));
     67   base::FilePath expected = profile_path.AppendASCII("Web Applications")
     68       .AppendASCII("example.com").AppendASCII("http_80");
     69   EXPECT_EQ(expected, result);
     70 }
     71