Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: chrome/browser/extensions/extension_menu_manager_unittest.cc

Issue 3210007: Add support for a "split" incognito behavior for extensions. (Closed)
Patch Set: latest Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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 <vector> 5 #include <vector>
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/scoped_vector.h" 10 #include "base/scoped_vector.h"
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 } 331 }
332 332
333 // A mock message service for tests of ExtensionMenuManager::ExecuteCommand. 333 // A mock message service for tests of ExtensionMenuManager::ExecuteCommand.
334 class MockExtensionMessageService : public ExtensionMessageService { 334 class MockExtensionMessageService : public ExtensionMessageService {
335 public: 335 public:
336 explicit MockExtensionMessageService(Profile* profile) : 336 explicit MockExtensionMessageService(Profile* profile) :
337 ExtensionMessageService(profile) {} 337 ExtensionMessageService(profile) {}
338 338
339 MOCK_METHOD4(DispatchEventToRenderers, void(const std::string& event_name, 339 MOCK_METHOD4(DispatchEventToRenderers, void(const std::string& event_name,
340 const std::string& event_args, 340 const std::string& event_args,
341 bool has_incognito_data, 341 Profile* source_profile,
342 const GURL& event_url)); 342 const GURL& event_url));
343 343
344 private: 344 private:
345 DISALLOW_COPY_AND_ASSIGN(MockExtensionMessageService); 345 DISALLOW_COPY_AND_ASSIGN(MockExtensionMessageService);
346 }; 346 };
347 347
348 // A mock profile for tests of ExtensionMenuManager::ExecuteCommand. 348 // A mock profile for tests of ExtensionMenuManager::ExecuteCommand.
349 class MockTestingProfile : public TestingProfile { 349 class MockTestingProfile : public TestingProfile {
350 public: 350 public:
351 MockTestingProfile() {} 351 MockTestingProfile() {}
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 406
407 Extension* extension = AddExtension("test"); 407 Extension* extension = AddExtension("test");
408 ExtensionMenuItem* item = CreateTestItem(extension); 408 ExtensionMenuItem* item = CreateTestItem(extension);
409 ExtensionMenuItem::Id id = item->id(); 409 ExtensionMenuItem::Id id = item->id();
410 ASSERT_TRUE(manager_.AddContextItem(extension, item)); 410 ASSERT_TRUE(manager_.AddContextItem(extension, item));
411 411
412 EXPECT_CALL(profile, GetExtensionMessageService()) 412 EXPECT_CALL(profile, GetExtensionMessageService())
413 .Times(1) 413 .Times(1)
414 .WillOnce(Return(mock_message_service.get())); 414 .WillOnce(Return(mock_message_service.get()));
415 415
416 EXPECT_CALL(profile, IsOffTheRecord())
417 .Times(AtLeast(1))
418 .WillRepeatedly(Return(false));
419
420 // Use the magic of googlemock to save a parameter to our mock's 416 // Use the magic of googlemock to save a parameter to our mock's
421 // DispatchEventToRenderers method into event_args. 417 // DispatchEventToRenderers method into event_args.
422 std::string event_args; 418 std::string event_args;
423 std::string expected_event_name = "contextMenus/" + item->extension_id(); 419 std::string expected_event_name = "contextMenus/" + item->extension_id();
424 EXPECT_CALL(*mock_message_service.get(), 420 EXPECT_CALL(*mock_message_service.get(),
425 DispatchEventToRenderers(expected_event_name, _, 421 DispatchEventToRenderers(expected_event_name, _,
426 profile.IsOffTheRecord(), 422 &profile,
427 GURL())) 423 GURL()))
428 .Times(1) 424 .Times(1)
429 .WillOnce(SaveArg<1>(&event_args)); 425 .WillOnce(SaveArg<1>(&event_args));
430 426
431 manager_.ExecuteCommand(&profile, NULL /* tab_contents */, params, id); 427 manager_.ExecuteCommand(&profile, NULL /* tab_contents */, params, id);
432 428
433 // Parse the json event_args, which should turn into a 2-element list where 429 // Parse the json event_args, which should turn into a 2-element list where
434 // the first element is a dictionary we want to inspect for the correct 430 // the first element is a dictionary we want to inspect for the correct
435 // values. 431 // values.
436 scoped_ptr<Value> result(base::JSONReader::Read(event_args, true)); 432 scoped_ptr<Value> result(base::JSONReader::Read(event_args, true));
(...skipping 18 matching lines...) Expand all
455 ASSERT_TRUE(info->GetString("pageUrl", &tmp)); 451 ASSERT_TRUE(info->GetString("pageUrl", &tmp));
456 ASSERT_EQ(params.page_url.spec(), tmp); 452 ASSERT_EQ(params.page_url.spec(), tmp);
457 453
458 ASSERT_TRUE(info->GetString("selectionText", &tmp)); 454 ASSERT_TRUE(info->GetString("selectionText", &tmp));
459 ASSERT_EQ(WideToUTF8(params.selection_text), tmp); 455 ASSERT_EQ(WideToUTF8(params.selection_text), tmp);
460 456
461 bool bool_tmp = true; 457 bool bool_tmp = true;
462 ASSERT_TRUE(info->GetBoolean("editable", &bool_tmp)); 458 ASSERT_TRUE(info->GetBoolean("editable", &bool_tmp));
463 ASSERT_EQ(params.is_editable, bool_tmp); 459 ASSERT_EQ(params.is_editable, bool_tmp);
464 } 460 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_menu_manager.cc ('k') | chrome/browser/extensions/extension_message_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698