| 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 "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" | 10 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" |
| 11 #include "chrome/browser/ui/web_applications/web_app_ui.h" | 11 #include "chrome/browser/ui/web_applications/web_app_ui.h" |
| 12 #include "chrome/common/extensions/extension_messages.h" | 12 #include "chrome/common/extensions/extension_messages.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
| 14 #include "content/test/test_browser_thread.h" | 14 #include "content/test/test_browser_thread.h" |
| 15 #include "content/test/test_renderer_host.h" | 15 #include "content/test/test_renderer_host.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 using content::BrowserThread; | 18 using content::BrowserThread; |
| 19 using content::RenderViewHostTester; |
| 19 | 20 |
| 20 class WebApplicationTest : public TabContentsWrapperTestHarness { | 21 class WebApplicationTest : public TabContentsWrapperTestHarness { |
| 21 public: | 22 public: |
| 22 WebApplicationTest() : ui_thread_(BrowserThread::UI, &message_loop_) { | 23 WebApplicationTest() : ui_thread_(BrowserThread::UI, &message_loop_) { |
| 23 } | 24 } |
| 24 | 25 |
| 25 private: | 26 private: |
| 26 content::TestBrowserThread ui_thread_; | 27 content::TestBrowserThread ui_thread_; |
| 27 }; | 28 }; |
| 28 | 29 |
| 29 TEST_F(WebApplicationTest, GetShortcutInfoForTab) { | 30 TEST_F(WebApplicationTest, GetShortcutInfoForTab) { |
| 30 const string16 title = ASCIIToUTF16("TEST_TITLE"); | 31 const string16 title = ASCIIToUTF16("TEST_TITLE"); |
| 31 const string16 description = ASCIIToUTF16("TEST_DESCRIPTION"); | 32 const string16 description = ASCIIToUTF16("TEST_DESCRIPTION"); |
| 32 const GURL url("http://www.foo.com/bar"); | 33 const GURL url("http://www.foo.com/bar"); |
| 33 WebApplicationInfo web_app_info; | 34 WebApplicationInfo web_app_info; |
| 34 web_app_info.title = title; | 35 web_app_info.title = title; |
| 35 web_app_info.description = description; | 36 web_app_info.description = description; |
| 36 web_app_info.app_url = url; | 37 web_app_info.app_url = url; |
| 37 | 38 |
| 38 rvh_tester()->TestOnMessageReceived( | 39 RenderViewHostTester::TestOnMessageReceived( |
| 40 rvh(), |
| 39 ExtensionHostMsg_DidGetApplicationInfo(0, 0, web_app_info)); | 41 ExtensionHostMsg_DidGetApplicationInfo(0, 0, web_app_info)); |
| 40 ShellIntegration::ShortcutInfo info; | 42 ShellIntegration::ShortcutInfo info; |
| 41 web_app::GetShortcutInfoForTab(contents_wrapper(), &info); | 43 web_app::GetShortcutInfoForTab(contents_wrapper(), &info); |
| 42 | 44 |
| 43 EXPECT_EQ(title, info.title); | 45 EXPECT_EQ(title, info.title); |
| 44 EXPECT_EQ(description, info.description); | 46 EXPECT_EQ(description, info.description); |
| 45 EXPECT_EQ(url, info.url); | 47 EXPECT_EQ(url, info.url); |
| 46 } | 48 } |
| 47 | 49 |
| 48 TEST_F(WebApplicationTest, AppDirWithId) { | 50 TEST_F(WebApplicationTest, AppDirWithId) { |
| 49 FilePath profile_path(FILE_PATH_LITERAL("profile")); | 51 FilePath profile_path(FILE_PATH_LITERAL("profile")); |
| 50 FilePath result(web_app::GetWebAppDataDirectory(profile_path, "123", GURL())); | 52 FilePath result(web_app::GetWebAppDataDirectory(profile_path, "123", GURL())); |
| 51 FilePath expected = profile_path.AppendASCII("Web Applications") | 53 FilePath expected = profile_path.AppendASCII("Web Applications") |
| 52 .AppendASCII("_crx_123"); | 54 .AppendASCII("_crx_123"); |
| 53 EXPECT_EQ(expected, result); | 55 EXPECT_EQ(expected, result); |
| 54 } | 56 } |
| 55 | 57 |
| 56 TEST_F(WebApplicationTest, AppDirWithUrl) { | 58 TEST_F(WebApplicationTest, AppDirWithUrl) { |
| 57 FilePath profile_path(FILE_PATH_LITERAL("profile")); | 59 FilePath profile_path(FILE_PATH_LITERAL("profile")); |
| 58 FilePath result(web_app::GetWebAppDataDirectory( | 60 FilePath result(web_app::GetWebAppDataDirectory( |
| 59 profile_path, "", GURL("http://example.com"))); | 61 profile_path, "", GURL("http://example.com"))); |
| 60 FilePath expected = profile_path.AppendASCII("Web Applications") | 62 FilePath expected = profile_path.AppendASCII("Web Applications") |
| 61 .AppendASCII("example.com") | 63 .AppendASCII("example.com") |
| 62 .AppendASCII("http_80"); | 64 .AppendASCII("http_80"); |
| 63 EXPECT_EQ(expected, result); | 65 EXPECT_EQ(expected, result); |
| 64 } | 66 } |
| OLD | NEW |