summaryrefslogtreecommitdiffstats
path: root/chrome/browser/web_applications/web_app_unittest.cc
blob: f41ac0d5da7cacd08d335f0e6407f7ddaa9f6ed3 (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
// Copyright (c) 2011 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/file_path.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h"
#include "chrome/browser/ui/web_applications/web_app_ui.h"
#include "chrome/common/extensions/extension_messages.h"
#include "chrome/test/base/testing_profile.h"
#include "content/test/test_browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h"

using content::BrowserThread;

class WebApplicationTest : public TabContentsWrapperTestHarness {
 public:
  WebApplicationTest() : ui_thread_(BrowserThread::UI, &message_loop_) {
  }

 private:
  content::TestBrowserThread ui_thread_;
};

TEST_F(WebApplicationTest, GetShortcutInfoForTab) {
  const string16 title = ASCIIToUTF16("TEST_TITLE");
  const string16 description = 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;

  rvh()->TestOnMessageReceived(
      ExtensionHostMsg_DidGetApplicationInfo(0, 0, web_app_info));
  ShellIntegration::ShortcutInfo info;
  web_app::GetShortcutInfoForTab(contents_wrapper(), &info);

  EXPECT_EQ(title, info.title);
  EXPECT_EQ(description, info.description);
  EXPECT_EQ(url, info.url);
}

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

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