summaryrefslogtreecommitdiffstats
path: root/chrome/browser/remoting/firewall_traversal_tab_helper_unittest.cc
blob: b74a150f67656b5c21a3baa43099ba79efe30f35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2011 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/remoting/firewall_traversal_tab_helper.h"

#include "chrome/browser/prefs/pref_service.h"
#include "content/browser/renderer_host/mock_render_process_host.h"
#include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
#include "content/browser/browser_thread.h"
#include "content/browser/tab_contents/test_tab_contents.h"
#include "content/common/notification_service.h"
#include "content/common/view_messages.h"
#include "ipc/ipc_message.h"

class FirewallTraversalTabHelperTest : public TabContentsWrapperTestHarness {
 public:
  FirewallTraversalTabHelperTest()
      : browser_thread_(BrowserThread::UI, &message_loop_) {}
  virtual ~FirewallTraversalTabHelperTest() {}

 private:
  BrowserThread browser_thread_;
};

// Test receiving message.
TEST_F(FirewallTraversalTabHelperTest, TestBasicMessage) {
  IPC::TestSink& sink = process()->sink();
  sink.ClearMessages();
  IPC::Message msg(MSG_ROUTING_NONE,
                   ViewHostMsg_RequestRemoteAccessClientFirewallTraversal::ID,
                   IPC::Message::PRIORITY_NORMAL);
  ASSERT_TRUE(active_rvh()->TestOnMessageReceived(msg));
  const IPC::Message* expect_msg = sink.GetUniqueMessageMatching(
      ViewMsg_UpdateRemoteAccessClientFirewallTraversal::ID);
  ASSERT_TRUE(expect_msg);
}

// Test changing preference.
TEST_F(FirewallTraversalTabHelperTest, TestPrefChange) {
  IPC::TestSink& sink = process()->sink();
  sink.ClearMessages();
  contents_wrapper()->profile()->GetPrefs()->SetBoolean(
      prefs::kRemoteAccessClientFirewallTraversal,
      false);
  const IPC::Message* expect_msg = sink.GetUniqueMessageMatching(
      ViewMsg_UpdateRemoteAccessClientFirewallTraversal::ID);
  ASSERT_TRUE(expect_msg);
}