summaryrefslogtreecommitdiffstats
path: root/chrome/browser/web_applications/web_app_unittest.cc
blob: 2cf437ba0069a6f8006342fb7931e24b39bfeec9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/web_applications/web_app.h"

#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/render_messages.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "content/public/test/test_renderer_host.h"
#include "testing/gtest/include/gtest/gtest.h"

#if defined(TOOLKIT_VIEWS)
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/favicon/favicon_utils.h"
#endif

using content::RenderViewHostTester;

class WebApplicationTest : public ChromeRenderViewHostTestHarness {
 protected:
  void SetUp() override {
    ChromeRenderViewHostTestHarness::SetUp();
#if defined(TOOLKIT_VIEWS)
    extensions::TabHelper::CreateForWebContents(web_contents());
    favicon::CreateContentFaviconDriverForWebContents(web_contents());
#endif
  }
};

#if defined(TOOLKIT_VIEWS)
TEST_F(WebApplicationTest, GetShortcutInfoForTab) {
  const base::string16 title = base::ASCIIToUTF16("TEST_TITLE");
  const base::string16 description = base::ASCIIToUTF16("TEST_DESCRIPTION");
  const GURL url("http://www.foo.com/bar");
  WebApplicationInfo web_app_info;
  web_app_info.title = title;
  web_app_info.description = description;
  web_app_info.app_url = url;

  content::RenderFrameHostTester::For(main_rfh())
      ->InitializeRenderFrameIfNeeded();
  RenderViewHostTester::TestOnMessageReceived(
      rvh(), ChromeViewHostMsg_DidGetWebApplicationInfo(0, web_app_info));
  scoped_ptr<web_app::ShortcutInfo> info =
      web_app::GetShortcutInfoForTab(web_contents());

  EXPECT_EQ(title, info->title);
  EXPECT_EQ(description, info->description);
  EXPECT_EQ(url, info->url);
}
#endif

#if defined(ENABLE_EXTENSIONS)
TEST_F(WebApplicationTest, AppDirWithId) {
  base::FilePath profile_path(FILE_PATH_LITERAL("profile"));
  base::FilePath result(
      web_app::GetWebAppDataDirectory(profile_path, "123", GURL()));
  base::FilePath expected = profile_path.AppendASCII("Web Applications")
                                  .AppendASCII("_crx_123");
  EXPECT_EQ(expected, result);
}

TEST_F(WebApplicationTest, AppDirWithUrl) {
  base::FilePath profile_path(FILE_PATH_LITERAL("profile"));
  base::FilePath result(web_app::GetWebAppDataDirectory(
      profile_path, std::string(), GURL("http://example.com")));
  base::FilePath expected = profile_path.AppendASCII("Web Applications")
      .AppendASCII("example.com").AppendASCII("http_80");
  EXPECT_EQ(expected, result);
}
#endif // ENABLE_EXTENSIONS