Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / web_applications / web_app_unittest.cc
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/web_applications/web_app.h"
11 #include "chrome/common/extensions/chrome_extension_messages.h"
12 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
13 #include "content/public/test/test_renderer_host.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 #if defined(TOOLKIT_VIEWS)
17 #include "chrome/browser/extensions/tab_helper.h"
18 #include "chrome/browser/favicon/favicon_tab_helper.h"
19 #endif
20
21 using content::RenderViewHostTester;
22
23 class WebApplicationTest : public ChromeRenderViewHostTestHarness {
24  protected:
25   virtual void SetUp() OVERRIDE {
26     ChromeRenderViewHostTestHarness::SetUp();
27 #if defined(TOOLKIT_VIEWS)
28     extensions::TabHelper::CreateForWebContents(web_contents());
29     FaviconTabHelper::CreateForWebContents(web_contents());
30 #endif
31   }
32 };
33
34 #if defined(TOOLKIT_VIEWS)
35 TEST_F(WebApplicationTest, GetShortcutInfoForTab) {
36   const base::string16 title = base::ASCIIToUTF16("TEST_TITLE");
37   const base::string16 description = base::ASCIIToUTF16("TEST_DESCRIPTION");
38   const GURL url("http://www.foo.com/bar");
39   WebApplicationInfo web_app_info;
40   web_app_info.title = title;
41   web_app_info.description = description;
42   web_app_info.app_url = url;
43
44   RenderViewHostTester::TestOnMessageReceived(
45       rvh(), ChromeExtensionHostMsg_DidGetApplicationInfo(0, web_app_info));
46   web_app::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 #endif
54
55 TEST_F(WebApplicationTest, AppDirWithId) {
56   base::FilePath profile_path(FILE_PATH_LITERAL("profile"));
57   base::FilePath result(
58       web_app::GetWebAppDataDirectory(profile_path, "123", GURL()));
59   base::FilePath expected = profile_path.AppendASCII("Web Applications")
60                                   .AppendASCII("_crx_123");
61   EXPECT_EQ(expected, result);
62 }
63
64 TEST_F(WebApplicationTest, AppDirWithUrl) {
65   base::FilePath profile_path(FILE_PATH_LITERAL("profile"));
66   base::FilePath result(web_app::GetWebAppDataDirectory(
67       profile_path, std::string(), GURL("http://example.com")));
68   base::FilePath expected = profile_path.AppendASCII("Web Applications")
69       .AppendASCII("example.com").AppendASCII("http_80");
70   EXPECT_EQ(expected, result);
71 }