1// Copyright (c) 2011 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#import <Cocoa/Cocoa.h>
6
7#import "base/memory/scoped_nsobject.h"
8#import "chrome/browser/ui/cocoa/about_ipc_controller.h"
9#include "chrome/browser/ui/cocoa/browser_test_helper.h"
10#include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
11#include "testing/gtest/include/gtest/gtest.h"
12#include "testing/platform_test.h"
13
14#if defined(IPC_MESSAGE_LOG_ENABLED)
15
16namespace {
17
18class AboutIPCControllerTest : public CocoaTest {
19};
20
21TEST_F(AboutIPCControllerTest, TestFilter) {
22  AboutIPCController* controller = [[AboutIPCController alloc] init];
23  EXPECT_TRUE([controller window]);  // force nib load.
24  IPC::LogData data;
25
26  // Make sure generic names do NOT get filtered.
27  std::string names[] = { "PluginProcessingIsMyLife",
28                          "ViewMsgFoo",
29                          "NPObjectHell" };
30  for (size_t i = 0; i < arraysize(names); i++) {
31    data.message_name = names[i];
32    scoped_nsobject<CocoaLogData> cdata([[CocoaLogData alloc]
33                                          initWithLogData:data]);
34    EXPECT_FALSE([controller filterOut:cdata.get()]);
35  }
36
37  // Flip a checkbox, see it filtered, flip back, all is fine.
38  data.message_name = "ViewMsgFoo";
39  scoped_nsobject<CocoaLogData> cdata([[CocoaLogData alloc]
40                                        initWithLogData:data]);
41  [controller setDisplayViewMessages:NO];
42  EXPECT_TRUE([controller filterOut:cdata.get()]);
43  [controller setDisplayViewMessages:YES];
44  EXPECT_FALSE([controller filterOut:cdata.get()]);
45  [controller close];
46}
47
48}  // namespace
49
50#endif  // IPC_MESSAGE_LOG_ENABLED
51