Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / web_applications / web_app_unittest.cc
blob38ef8961e2af8975cb8685870d2dad1db28bb935
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.
5 #include "chrome/browser/web_applications/web_app.h"
7 #include "base/files/file_path.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/web_applications/web_app.h"
12 #include "chrome/common/render_messages.h"
13 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
14 #include "content/public/test/test_renderer_host.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 #if defined(TOOLKIT_VIEWS)
18 #include "chrome/browser/extensions/tab_helper.h"
19 #include "chrome/browser/favicon/favicon_utils.h"
20 #endif
22 using content::RenderViewHostTester;
24 class WebApplicationTest : public ChromeRenderViewHostTestHarness {
25 protected:
26 void SetUp() override {
27 ChromeRenderViewHostTestHarness::SetUp();
28 #if defined(TOOLKIT_VIEWS)
29 extensions::TabHelper::CreateForWebContents(web_contents());
30 favicon::CreateContentFaviconDriverForWebContents(web_contents());
31 #endif
35 #if defined(TOOLKIT_VIEWS)
36 TEST_F(WebApplicationTest, GetShortcutInfoForTab) {
37 const base::string16 title = base::ASCIIToUTF16("TEST_TITLE");
38 const base::string16 description = base::ASCIIToUTF16("TEST_DESCRIPTION");
39 const GURL url("http://www.foo.com/bar");
40 WebApplicationInfo web_app_info;
41 web_app_info.title = title;
42 web_app_info.description = description;
43 web_app_info.app_url = url;
45 RenderViewHostTester::TestOnMessageReceived(
46 rvh(), ChromeViewHostMsg_DidGetWebApplicationInfo(0, web_app_info));
47 scoped_ptr<web_app::ShortcutInfo> info =
48 web_app::GetShortcutInfoForTab(web_contents());
50 EXPECT_EQ(title, info->title);
51 EXPECT_EQ(description, info->description);
52 EXPECT_EQ(url, info->url);
54 #endif
56 #if defined(ENABLE_EXTENSIONS)
57 TEST_F(WebApplicationTest, AppDirWithId) {
58 base::FilePath profile_path(FILE_PATH_LITERAL("profile"));
59 base::FilePath result(
60 web_app::GetWebAppDataDirectory(profile_path, "123", GURL()));
61 base::FilePath expected = profile_path.AppendASCII("Web Applications")
62 .AppendASCII("_crx_123");
63 EXPECT_EQ(expected, result);
66 TEST_F(WebApplicationTest, AppDirWithUrl) {
67 base::FilePath profile_path(FILE_PATH_LITERAL("profile"));
68 base::FilePath result(web_app::GetWebAppDataDirectory(
69 profile_path, std::string(), GURL("http://example.com")));
70 base::FilePath expected = profile_path.AppendASCII("Web Applications")
71 .AppendASCII("example.com").AppendASCII("http_80");
72 EXPECT_EQ(expected, result);
74 #endif // ENABLE_EXTENSIONS