| 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/ui/ash/launcher/chrome_launcher_controller_per_app.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/launcher/launcher_model.h" | 11 #include "ash/launcher/launcher_model.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
| 20 #include "chrome/browser/extensions/test_extension_system.h" | 20 #include "chrome/browser/extensions/test_extension_system.h" |
| 21 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" | 21 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" |
| 22 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" | 22 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" |
| 23 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/browser/ui/browser_commands.h" | 24 #include "chrome/browser/ui/browser_commands.h" |
| 24 #include "chrome/browser/ui/browser_finder.h" | 25 #include "chrome/browser/ui/browser_finder.h" |
| 25 #include "chrome/browser/ui/browser_list.h" | 26 #include "chrome/browser/ui/browser_list.h" |
| 27 #include "chrome/browser/ui/host_desktop.h" |
| 26 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 28 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 27 #include "chrome/common/extensions/extension.h" | 29 #include "chrome/common/extensions/extension.h" |
| 28 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 29 #include "chrome/test/base/browser_with_test_window_test.h" | 31 #include "chrome/test/base/browser_with_test_window_test.h" |
| 30 #include "chrome/test/base/testing_pref_service_syncable.h" | 32 #include "chrome/test/base/testing_pref_service_syncable.h" |
| 31 #include "chrome/test/base/testing_profile.h" | 33 #include "chrome/test/base/testing_profile.h" |
| 32 #include "content/public/test/test_browser_thread.h" | 34 #include "content/public/test/test_browser_thread.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 34 #include "ui/base/models/menu_model.h" | 36 #include "ui/base/models/menu_model.h" |
| 35 | 37 |
| 36 using extensions::Extension; | 38 using extensions::Extension; |
| 37 using extensions::Manifest; | 39 using extensions::Manifest; |
| 38 | 40 |
| 39 namespace { | 41 namespace { |
| 40 const int kExpectedAppIndex = 1; | 42 const int kExpectedAppIndex = 1; |
| 41 const char* gmail_app_id = "pjkljhegncpnkpknbcohdijeoejaedia"; | 43 const char* gmail_app_id = "pjkljhegncpnkpknbcohdijeoejaedia"; |
| 42 const char* gmail_url = "https://mail.google.com/mail/u"; | 44 const char* gmail_url = "https://mail.google.com/mail/u"; |
| 43 } | 45 } |
| 44 | 46 |
| 45 class ChromeLauncherControllerPerAppTest : public BrowserWithTestWindowTest { | 47 class ChromeLauncherControllerPerAppTest : public BrowserWithTestWindowTest { |
| 46 protected: | 48 protected: |
| 47 ChromeLauncherControllerPerAppTest() : extension_service_(NULL) { | 49 ChromeLauncherControllerPerAppTest() |
| 50 : BrowserWithTestWindowTest(chrome::HOST_DESKTOP_TYPE_ASH), |
| 51 extension_service_(NULL) { |
| 48 } | 52 } |
| 49 | 53 |
| 50 virtual void SetUp() OVERRIDE { | 54 virtual void SetUp() OVERRIDE { |
| 51 BrowserWithTestWindowTest::SetUp(); | 55 BrowserWithTestWindowTest::SetUp(); |
| 52 | 56 |
| 53 DictionaryValue manifest; | 57 DictionaryValue manifest; |
| 54 manifest.SetString("name", "launcher controller test extension"); | 58 manifest.SetString("name", "launcher controller test extension"); |
| 55 manifest.SetString("version", "1"); | 59 manifest.SetString("version", "1"); |
| 56 manifest.SetString("description", "for testing pinned apps"); | 60 manifest.SetString("description", "for testing pinned apps"); |
| 57 | 61 |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 335 |
| 332 // Now make the created browser() visible by adding it to the active browser | 336 // Now make the created browser() visible by adding it to the active browser |
| 333 // list. | 337 // list. |
| 334 BrowserList::SetLastActive(browser()); | 338 BrowserList::SetLastActive(browser()); |
| 335 string16 title1 = ASCIIToUTF16("Test1"); | 339 string16 title1 = ASCIIToUTF16("Test1"); |
| 336 NavigateAndCommitActiveTabWithTitle(browser(), GURL("http://test1"), title1); | 340 NavigateAndCommitActiveTabWithTitle(browser(), GURL("http://test1"), title1); |
| 337 string16 one_menu_item[] = {title1}; | 341 string16 one_menu_item[] = {title1}; |
| 338 CheckMenuCreation(&launcher_controller, item_browser, 1, one_menu_item, true); | 342 CheckMenuCreation(&launcher_controller, item_browser, 1, one_menu_item, true); |
| 339 | 343 |
| 340 // Create one more browser/window and check that one more was added. | 344 // Create one more browser/window and check that one more was added. |
| 345 Browser::CreateParams ash_params(profile(), chrome::HOST_DESKTOP_TYPE_ASH); |
| 341 scoped_ptr<Browser> browser2( | 346 scoped_ptr<Browser> browser2( |
| 342 chrome::CreateBrowserWithTestWindowForProfile(profile())); | 347 chrome::CreateBrowserWithTestWindowForParams(&ash_params)); |
| 343 chrome::NewTab(browser2.get()); | 348 chrome::NewTab(browser2.get()); |
| 344 BrowserList::SetLastActive(browser2.get()); | 349 BrowserList::SetLastActive(browser2.get()); |
| 345 string16 title2 = ASCIIToUTF16("Test2"); | 350 string16 title2 = ASCIIToUTF16("Test2"); |
| 346 NavigateAndCommitActiveTabWithTitle(browser2.get(), GURL("http://test2"), | 351 NavigateAndCommitActiveTabWithTitle(browser2.get(), GURL("http://test2"), |
| 347 title2); | 352 title2); |
| 348 | 353 |
| 349 // Check that the list contains now two entries - make furthermore sure that | 354 // Check that the list contains now two entries - make furthermore sure that |
| 350 // the active item is the first entry. | 355 // the active item is the first entry. |
| 351 string16 two_menu_items[] = {title2, title1}; | 356 string16 two_menu_items[] = {title2, title1}; |
| 352 CheckMenuCreation(&launcher_controller, | 357 CheckMenuCreation(&launcher_controller, |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 { | 487 { |
| 483 scoped_ptr<ui::MenuModel> menu( | 488 scoped_ptr<ui::MenuModel> menu( |
| 484 launcher_controller.CreateApplicationMenu(item_gmail)); | 489 launcher_controller.CreateApplicationMenu(item_gmail)); |
| 485 int first_item = | 490 int first_item = |
| 486 (menu->GetTypeAt(0) == ui::MenuModel::TYPE_SEPARATOR) ? 1 : 0; | 491 (menu->GetTypeAt(0) == ui::MenuModel::TYPE_SEPARATOR) ? 1 : 0; |
| 487 menu->ActivatedAt(first_item + 3); | 492 menu->ActivatedAt(first_item + 3); |
| 488 } | 493 } |
| 489 // Now the active tab should be the second item. | 494 // Now the active tab should be the second item. |
| 490 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); | 495 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); |
| 491 } | 496 } |
| OLD | NEW |