Home | History | Annotate | Download | only in rtc_private
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/chromeos/contacts/contact.pb.h"
      6 #include "chrome/browser/extensions/api/rtc_private/rtc_private_api.h"
      7 #include "chrome/browser/extensions/extension_apitest.h"
      8 #include "chrome/browser/extensions/extension_service.h"
      9 #include "chrome/browser/extensions/extension_test_message_listener.h"
     10 #include "chrome/browser/ui/browser.h"
     11 #include "chrome/common/chrome_switches.h"
     12 #include "chrome/common/extensions/extension.h"
     13 #include "chrome/test/base/ui_test_utils.h"
     14 #include "content/public/browser/web_contents.h"
     15 #include "content/public/test/browser_test_utils.h"
     16 #include "url/gurl.h"
     17 
     18 namespace {
     19 
     20 // Id of test extension from
     21 // chrome/test/data/extensions/api_test/rtc_private/events.
     22 const char kTestRtcExtensionId[] = "jdaiaafaoeaejklkkbndacnggmgmpkpa";
     23 // Test contact data.
     24 const char kContactFullName[] = "Test Contact";
     25 const char kTestEmail_1[] = "test_1 (at) something.com";
     26 const char kTestEmail_2[] = "test_2 (at) something.com";
     27 const char kTestPhone_1[] = "(555) 111-2222";
     28 const char kTestPhone_2[] = "(555) 333-4444";
     29 
     30 }  // namespace
     31 
     32 class RtcPrivateApiTest : public ExtensionApiTest {
     33  protected:
     34   // ExtensionApiTest overrides.
     35   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
     36     ExtensionApiTest::SetUpCommandLine(command_line);
     37     command_line->AppendSwitchASCII(switches::kWhitelistedExtensionID,
     38                                     kTestRtcExtensionId);
     39     command_line->AppendSwitch(switches::kEnableContacts);
     40   }
     41 
     42   static contacts::Contact* CreateTestContact() {
     43     contacts::Contact* contact = new contacts::Contact();
     44     contact->set_full_name(kContactFullName);
     45     contacts::Contact_EmailAddress* address_1 =
     46         contact->mutable_email_addresses()->Add();
     47     address_1->set_address(kTestEmail_1);
     48     contacts::Contact_EmailAddress* address_2 =
     49         contact->mutable_email_addresses()->Add();
     50     address_2->set_address(kTestEmail_2);
     51 
     52     contacts::Contact_PhoneNumber* number_1 =
     53         contact->mutable_phone_numbers()->Add();
     54     number_1->set_number(kTestPhone_1);
     55     contacts::Contact_PhoneNumber* number_2 =
     56         contact->mutable_phone_numbers()->Add();
     57     number_2->set_number(kTestPhone_2);
     58     return contact;
     59   }
     60 };
     61 
     62 IN_PROC_BROWSER_TEST_F(RtcPrivateApiTest, LaunchEvents) {
     63   // Load test RTC extension.
     64   const extensions::Extension* extension = LoadExtension(
     65       test_data_dir_.AppendASCII("rtc_private/events"));
     66   ASSERT_TRUE(extension);
     67 
     68   ExtensionTestMessageListener discovery_started("received_all", false);
     69 
     70   // Raise all RTC-related events.
     71   scoped_ptr<contacts::Contact> contact(CreateTestContact());
     72   extensions::RtcPrivateEventRouter::DispatchLaunchEvent(
     73       browser()->profile(),
     74       extensions::RtcPrivateEventRouter::LAUNCH_ACTIVATE,
     75       contact.get());
     76 
     77   extensions::RtcPrivateEventRouter::DispatchLaunchEvent(
     78       browser()->profile(),
     79       extensions::RtcPrivateEventRouter::LAUNCH_CHAT,
     80       contact.get());
     81 
     82   extensions::RtcPrivateEventRouter::DispatchLaunchEvent(
     83       browser()->profile(),
     84       extensions::RtcPrivateEventRouter::LAUNCH_VIDEO,
     85       contact.get());
     86 
     87   extensions::RtcPrivateEventRouter::DispatchLaunchEvent(
     88       browser()->profile(),
     89       extensions::RtcPrivateEventRouter::LAUNCH_VOICE,
     90       contact.get());
     91 
     92   EXPECT_TRUE(discovery_started.WaitUntilSatisfied());
     93 }
     94