OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/web_applications/web_app.h" | 5 #include "chrome/browser/web_applications/web_app.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/browser/web_applications/web_app.h" | 12 #include "chrome/browser/web_applications/web_app.h" |
13 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" |
14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
15 #include "content/public/test/test_renderer_host.h" | 15 #include "content/public/test/test_renderer_host.h" |
16 #include "extensions/features/features.h" | 16 #include "extensions/features/features.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 #if defined(TOOLKIT_VIEWS) | 19 #if defined(TOOLKIT_VIEWS) |
20 #include "chrome/browser/extensions/tab_helper.h" | 20 #include "chrome/browser/extensions/tab_helper.h" |
21 #include "chrome/browser/favicon/favicon_utils.h" | 21 #include "chrome/browser/favicon/favicon_utils.h" |
22 #endif | 22 #endif |
23 | 23 |
24 using content::RenderViewHostTester; | 24 using content::RenderViewHostTester; |
alexmos
2017/06/20 22:44:11
nit: not needed anymore?
Łukasz Anforowicz
2017/06/20 23:19:15
Done.
| |
25 | 25 |
26 class WebApplicationTest : public ChromeRenderViewHostTestHarness { | 26 class WebApplicationTest : public ChromeRenderViewHostTestHarness { |
27 protected: | 27 protected: |
28 void SetUp() override { | 28 void SetUp() override { |
29 ChromeRenderViewHostTestHarness::SetUp(); | 29 ChromeRenderViewHostTestHarness::SetUp(); |
30 #if defined(TOOLKIT_VIEWS) | 30 #if defined(TOOLKIT_VIEWS) |
31 extensions::TabHelper::CreateForWebContents(web_contents()); | 31 extensions::TabHelper::CreateForWebContents(web_contents()); |
32 favicon::CreateContentFaviconDriverForWebContents(web_contents()); | 32 favicon::CreateContentFaviconDriverForWebContents(web_contents()); |
33 #endif | 33 #endif |
34 } | 34 } |
35 }; | 35 }; |
36 | 36 |
37 #if defined(TOOLKIT_VIEWS) | 37 #if defined(TOOLKIT_VIEWS) |
38 TEST_F(WebApplicationTest, GetShortcutInfoForTab) { | 38 TEST_F(WebApplicationTest, GetShortcutInfoForTab) { |
39 const base::string16 title = base::ASCIIToUTF16("TEST_TITLE"); | 39 const base::string16 title = base::ASCIIToUTF16("TEST_TITLE"); |
40 const base::string16 description = base::ASCIIToUTF16("TEST_DESCRIPTION"); | 40 const base::string16 description = base::ASCIIToUTF16("TEST_DESCRIPTION"); |
41 const GURL url("http://www.foo.com/bar"); | 41 const GURL url("http://www.foo.com/bar"); |
42 WebApplicationInfo web_app_info; | 42 WebApplicationInfo web_app_info; |
43 web_app_info.title = title; | 43 web_app_info.title = title; |
44 web_app_info.description = description; | 44 web_app_info.description = description; |
45 web_app_info.app_url = url; | 45 web_app_info.app_url = url; |
46 | 46 |
47 content::RenderFrameHostTester::For(main_rfh()) | 47 content::RenderFrameHostTester::For(main_rfh()) |
48 ->InitializeRenderFrameIfNeeded(); | 48 ->InitializeRenderFrameIfNeeded(); |
49 RenderViewHostTester::TestOnMessageReceived( | 49 content::RenderFrameHostTester::TestOnMessageReceived( |
50 rvh(), ChromeViewHostMsg_DidGetWebApplicationInfo(0, web_app_info)); | 50 rvh()->GetMainFrame(), |
alexmos
2017/06/20 22:44:11
nit: can shorten to main_rfh() (like above)
Łukasz Anforowicz
2017/06/20 23:19:15
Done.
| |
51 ChromeFrameHostMsg_DidGetWebApplicationInfo(0, web_app_info)); | |
51 std::unique_ptr<web_app::ShortcutInfo> info = | 52 std::unique_ptr<web_app::ShortcutInfo> info = |
52 web_app::GetShortcutInfoForTab(web_contents()); | 53 web_app::GetShortcutInfoForTab(web_contents()); |
53 | 54 |
54 EXPECT_EQ(title, info->title); | 55 EXPECT_EQ(title, info->title); |
55 EXPECT_EQ(description, info->description); | 56 EXPECT_EQ(description, info->description); |
56 EXPECT_EQ(url, info->url); | 57 EXPECT_EQ(url, info->url); |
57 } | 58 } |
58 #endif | 59 #endif |
59 | 60 |
60 #if BUILDFLAG(ENABLE_EXTENSIONS) | 61 #if BUILDFLAG(ENABLE_EXTENSIONS) |
61 TEST_F(WebApplicationTest, AppDirWithId) { | 62 TEST_F(WebApplicationTest, AppDirWithId) { |
62 base::FilePath profile_path(FILE_PATH_LITERAL("profile")); | 63 base::FilePath profile_path(FILE_PATH_LITERAL("profile")); |
63 base::FilePath result( | 64 base::FilePath result( |
64 web_app::GetWebAppDataDirectory(profile_path, "123", GURL())); | 65 web_app::GetWebAppDataDirectory(profile_path, "123", GURL())); |
65 base::FilePath expected = profile_path.AppendASCII("Web Applications") | 66 base::FilePath expected = profile_path.AppendASCII("Web Applications") |
66 .AppendASCII("_crx_123"); | 67 .AppendASCII("_crx_123"); |
67 EXPECT_EQ(expected, result); | 68 EXPECT_EQ(expected, result); |
68 } | 69 } |
69 | 70 |
70 TEST_F(WebApplicationTest, AppDirWithUrl) { | 71 TEST_F(WebApplicationTest, AppDirWithUrl) { |
71 base::FilePath profile_path(FILE_PATH_LITERAL("profile")); | 72 base::FilePath profile_path(FILE_PATH_LITERAL("profile")); |
72 base::FilePath result(web_app::GetWebAppDataDirectory( | 73 base::FilePath result(web_app::GetWebAppDataDirectory( |
73 profile_path, std::string(), GURL("http://example.com"))); | 74 profile_path, std::string(), GURL("http://example.com"))); |
74 base::FilePath expected = profile_path.AppendASCII("Web Applications") | 75 base::FilePath expected = profile_path.AppendASCII("Web Applications") |
75 .AppendASCII("example.com").AppendASCII("http_80"); | 76 .AppendASCII("example.com").AppendASCII("http_80"); |
76 EXPECT_EQ(expected, result); | 77 EXPECT_EQ(expected, result); |
77 } | 78 } |
78 #endif // ENABLE_EXTENSIONS | 79 #endif // ENABLE_EXTENSIONS |
OLD | NEW |