diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-25 21:39:07 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-25 21:39:07 +0000 |
commit | be3df2bcd2502eb0ff563a1fe7b760ed68182eae (patch) | |
tree | 5788cc342f110296b3bc5d317ffa964bb7255e55 /chrome/browser | |
parent | 9c8f1501112092eba0e1c411c2c196487eb61b00 (diff) | |
download | chromium_src-be3df2bcd2502eb0ff563a1fe7b760ed68182eae.zip chromium_src-be3df2bcd2502eb0ff563a1fe7b760ed68182eae.tar.gz chromium_src-be3df2bcd2502eb0ff563a1fe7b760ed68182eae.tar.bz2 |
Add tests for chrome/browser/web_applications and mark some code as Win32 and/or Views only. (TTF)
BUG=none
TEST=included.
Review URL: http://codereview.chromium.org/2826019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50897 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/web_applications/web_app.cc | 10 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app.h | 9 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app_unittest.cc | 63 |
3 files changed, 75 insertions, 7 deletions
diff --git a/chrome/browser/web_applications/web_app.cc b/chrome/browser/web_applications/web_app.cc index fce3da3..97a2329 100644 --- a/chrome/browser/web_applications/web_app.cc +++ b/chrome/browser/web_applications/web_app.cc @@ -5,7 +5,7 @@ #include "chrome/browser/web_applications/web_app.h" #if defined(OS_WIN) -#include <ShellAPI.h> +#include <shellapi.h> #endif // defined(OS_WIN) #include <algorithm> @@ -43,6 +43,7 @@ namespace { +#if defined(OS_WIN) const FilePath::CharType kIconChecksumFileExt[] = FILE_PATH_LITERAL(".ico.md5"); // Returns true if |ch| is in visible ASCII range and not one of @@ -81,12 +82,9 @@ FilePath GetSanitizedFileName(const string16& name) { file_name += c; } -#if defined(OS_WIN) return FilePath(file_name); -#elif defined(OS_POSIX) - return FilePath(UTF16ToUTF8(file_name)); -#endif } +#endif // defined(OS_WIN) // Returns relative directory of given web app url. FilePath GetWebAppDir(const GURL& url) { @@ -720,6 +718,7 @@ FilePath GetDataDir(const FilePath& profile_path) { return profile_path.Append(chrome::kWebAppDirname); } +#if defined(TOOLKIT_VIEWS) void GetIconsInfo(const webkit_glue::WebApplicationInfo& app_info, IconInfoList* icons) { DCHECK(icons); @@ -734,6 +733,7 @@ void GetIconsInfo(const webkit_glue::WebApplicationInfo& app_info, std::sort(icons->begin(), icons->end(), &IconPrecedes); } +#endif void GetShortcutInfoForTab(TabContents* tab_contents, ShellIntegration::ShortcutInfo* info) { diff --git a/chrome/browser/web_applications/web_app.h b/chrome/browser/web_applications/web_app.h index f5d7f431..abe5b93 100644 --- a/chrome/browser/web_applications/web_app.h +++ b/chrome/browser/web_applications/web_app.h @@ -1,15 +1,18 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. #ifndef CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ #define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ +#include <vector> + #include "base/callback.h" -#include "base/file_path.h" +#include "build/build_config.h" #include "chrome/browser/shell_integration.h" #include "webkit/glue/dom_operations.h" +class FilePath; class Profile; class TabContents; @@ -40,11 +43,13 @@ bool IsValidUrl(const GURL& url); // Returns data dir for web apps for given profile path. FilePath GetDataDir(const FilePath& profile_path); +#if defined(TOOLKIT_VIEWS) // Extracts icons info from web app data. Take only square shaped icons and // sort them from smallest to largest. typedef std::vector<webkit_glue::WebApplicationInfo::IconInfo> IconInfoList; void GetIconsInfo(const webkit_glue::WebApplicationInfo& app_info, IconInfoList* icons); +#endif // Extracts shortcut info of given TabContents. void GetShortcutInfoForTab(TabContents* tab_contents, diff --git a/chrome/browser/web_applications/web_app_unittest.cc b/chrome/browser/web_applications/web_app_unittest.cc new file mode 100644 index 0000000..5908e88 --- /dev/null +++ b/chrome/browser/web_applications/web_app_unittest.cc @@ -0,0 +1,63 @@ +// Copyright (c) 2010 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 "chrome/browser/renderer_host/test/test_render_view_host.h" +#include "chrome/common/render_messages.h" +#include "chrome/test/testing_profile.h" +#include "testing/gtest/include/gtest/gtest.h" + +class WebApplicationTest : public RenderViewHostTestHarness { + public: + WebApplicationTest() + : RenderViewHostTestHarness(), + ui_thread_(ChromeThread::UI, &message_loop_) { + } + + private: + // Supply our own profile so we use the correct profile data. The test harness + // is not supposed to overwrite a profile if it's already created. + virtual void SetUp() { + profile_.reset(new TestingProfile()); + + RenderViewHostTestHarness::SetUp(); + } + + virtual void TearDown() { + RenderViewHostTestHarness::TearDown(); + + profile_.reset(NULL); + } + + ChromeThread 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"); + webkit_glue::WebApplicationInfo web_app_info; + web_app_info.title = title; + web_app_info.description = description; + web_app_info.app_url = url; + + rvh()->TestOnMessageReceived( + ViewHostMsg_DidGetApplicationInfo(0, 0, web_app_info)); + ShellIntegration::ShortcutInfo info; + web_app::GetShortcutInfoForTab(contents(), &info); + + EXPECT_EQ(title, info.title); + EXPECT_EQ(description, info.description); + EXPECT_EQ(url, info.url); +} + +TEST_F(WebApplicationTest, GetDataDir) { + FilePath test_path(FILE_PATH_LITERAL("/path/to/test")); + FilePath result = web_app::GetDataDir(FilePath(FILE_PATH_LITERAL(test_path))); + test_path = test_path.AppendASCII("Web Applications"); + EXPECT_EQ(test_path.value(), result.value()); +} |