web_app_unittest.cc revision c407dc5cd9bdc5668497f21b26b09d988ab439de
1// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/web_applications/web_app.h" 6 7#include "base/file_path.h" 8#include "base/string_util.h" 9#include "chrome/browser/renderer_host/test/test_render_view_host.h" 10#include "chrome/common/render_messages.h" 11#include "chrome/test/testing_profile.h" 12#include "testing/gtest/include/gtest/gtest.h" 13 14class WebApplicationTest : public RenderViewHostTestHarness { 15 public: 16 WebApplicationTest() 17 : RenderViewHostTestHarness(), 18 ui_thread_(ChromeThread::UI, &message_loop_) { 19 } 20 21 private: 22 // Supply our own profile so we use the correct profile data. The test harness 23 // is not supposed to overwrite a profile if it's already created. 24 virtual void SetUp() { 25 profile_.reset(new TestingProfile()); 26 27 RenderViewHostTestHarness::SetUp(); 28 } 29 30 virtual void TearDown() { 31 RenderViewHostTestHarness::TearDown(); 32 33 profile_.reset(NULL); 34 } 35 36 ChromeThread ui_thread_; 37}; 38 39TEST_F(WebApplicationTest, GetShortcutInfoForTab) { 40 const string16 title = ASCIIToUTF16("TEST_TITLE"); 41 const string16 description = ASCIIToUTF16("TEST_DESCRIPTION"); 42 const GURL url("http://www.foo.com/bar"); 43 webkit_glue::WebApplicationInfo web_app_info; 44 web_app_info.title = title; 45 web_app_info.description = description; 46 web_app_info.app_url = url; 47 48 rvh()->TestOnMessageReceived( 49 ViewHostMsg_DidGetApplicationInfo(0, 0, web_app_info)); 50 ShellIntegration::ShortcutInfo info; 51 web_app::GetShortcutInfoForTab(contents(), &info); 52 53 EXPECT_EQ(title, info.title); 54 EXPECT_EQ(description, info.description); 55 EXPECT_EQ(url, info.url); 56} 57 58TEST_F(WebApplicationTest, GetDataDir) { 59 FilePath test_path(FILE_PATH_LITERAL("/path/to/test")); 60 FilePath result = web_app::GetDataDir(test_path); 61 test_path = test_path.AppendASCII("Web Applications"); 62 EXPECT_EQ(test_path.value(), result.value()); 63} 64