<commit_before>// Copyright (c) 2009 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.

#import <Cocoa/Cocoa.h>

#include "base/ref_counted.h"
#import "chrome/browser/cocoa/bug_report_window_controller.h"
#include "chrome/browser/renderer_host/site_instance.h"
#include "chrome/browser/renderer_host/test/test_render_view_host.h"
#include "chrome/browser/tab_contents/test_tab_contents.h"
#include "chrome/browser/profile.h"

namespace {

class BugReportWindowControllerUnittest : public RenderViewHostTestHarness {
};

TEST_F(BugReportWindowControllerUnittest, ReportBugWithNewTabPageOpen) {
  ChromeThread ui_thread(ChromeThread::UI, MessageLoop::current());
  // Create a "chrome://newtab" test tab.  SiteInstance will be deleted when
  // tabContents is deleted.
  SiteInstance* instance =
      SiteInstance::CreateSiteInstance(profile_.get());
  TestTabContents* tabContents = new TestTabContents(profile_.get(),
                                                      instance);
  tabContents->controller().LoadURL(GURL("chrome://newtab"),
      GURL(), PageTransition::START_PAGE);

  BugReportWindowController* controller = [[BugReportWindowController alloc]
      initWithTabContents:tabContents
                  profile:profile_.get()];

  // The phishing report bug is stored at index 2 in the Report Bug dialog.
  [controller setBugTypeIndex:2];
  EXPECT_TRUE([controller isPhishingReport]);
  [controller setBugTypeIndex:1];
  EXPECT_FALSE([controller isPhishingReport]);

  // Make sure that the tab was correctly recorded.
  EXPECT_TRUE([[controller pageURL] isEqualToString:@"chrome://newtab/"]);
  EXPECT_TRUE([[controller pageTitle] isEqualToString:@"New Tab"]);

  // When we call "report bug" with non-empty tab contents, all menu options
  // should be available, and we should send screenshot by default.
  EXPECT_EQ([[controller bugTypeList] count], 8U);
  EXPECT_TRUE([controller sendScreenshot]);

  delete tabContents;
  [controller release];
}

TEST_F(BugReportWindowControllerUnittest, ReportBugWithNoWindowOpen) {
  BugReportWindowController* controller = [[BugReportWindowController alloc]
      initWithTabContents:NULL
                  profile:profile_.get()];

  // Make sure that no page title or URL are recorded. Note that IB reports
  // empty textfields as NULL values.<commit_msg>Disable BugReportWindowController tests. BUG=http://crbug.com/29019<commit_after>// Copyright (c) 2009 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.

#import <Cocoa/Cocoa.h>

#include "base/ref_counted.h"
#import "chrome/browser/cocoa/bug_report_window_controller.h"
#include "chrome/browser/renderer_host/site_instance.h"
#include "chrome/browser/renderer_host/test/test_render_view_host.h"
#include "chrome/browser/tab_contents/test_tab_contents.h"
#include "chrome/browser/profile.h"

namespace {

class BugReportWindowControllerUnittest : public RenderViewHostTestHarness {
};

// See http://crbug.com/29019 for why it's disabled.
TEST_F(BugReportWindowControllerUnittest, DISABLED_ReportBugWithNewTabPageOpen) {
  ChromeThread ui_thread(ChromeThread::UI, MessageLoop::current());
  // Create a "chrome://newtab" test tab.  SiteInstance will be deleted when
  // tabContents is deleted.
  SiteInstance* instance =
      SiteInstance::CreateSiteInstance(profile_.get());
  TestTabContents* tabContents = new TestTabContents(profile_.get(),
                                                      instance);
  tabContents->controller().LoadURL(GURL("chrome://newtab"),
      GURL(), PageTransition::START_PAGE);

  BugReportWindowController* controller = [[BugReportWindowController alloc]
      initWithTabContents:tabContents
                  profile:profile_.get()];

  // The phishing report bug is stored at index 2 in the Report Bug dialog.
  [controller setBugTypeIndex:2];
  EXPECT_TRUE([controller isPhishingReport]);
  [controller setBugTypeIndex:1];
  EXPECT_FALSE([controller isPhishingReport]);

  // Make sure that the tab was correctly recorded.
  EXPECT_TRUE([[controller pageURL] isEqualToString:@"chrome://newtab/"]);
  EXPECT_TRUE([[controller pageTitle] isEqualToString:@"New Tab"]);

  // When we call "report bug" with non-empty tab contents, all menu options
  // should be available, and we should send screenshot by default.
  EXPECT_EQ([[controller bugTypeList] count], 8U);
  EXPECT_TRUE([controller sendScreenshot]);

  delete tabContents;
  [controller release];
}

// See http://crbug.com/29019 for why it's disabled.
TEST_F(BugReportWindowControllerUnittest, DISABLED_ReportBugWithNoWindowOpen) {
  BugReportWindowController* controller = [[BugReportWindowController alloc]
      initWithTabContents:NULL
                  profile:profile_.get()];

  // Make sure that no page title or URL are recorded. Note that IB reports
  // empty textfields as NULL values.
{'fraction_non_alphanumeric': 0.1015562649640862, 'fraction_numerical': 0.006185155626496409, 'mean_word_length': 4.407766990291262, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4822184', 'n_tokens_mistral': 1435, 'n_tokens_neox': 1379, 'n_words': 372}