shill: Delete existing routes when the device is started.

BUG=chromium-os:27358
TEST=Unit tests, network_WiFiManager, manually add foreign routes and
ensure they are deleted, also test to make sure default route remains
after DHCP renewal

Change-Id: Ic26b70d685491f31699ff4684ed289e76af8a9ca
Reviewed-on: https://gerrit.chromium.org/gerrit/17640
Commit-Ready: Thieu Le <thieule@chromium.org>
Reviewed-by: Thieu Le <thieule@chromium.org>
Tested-by: Thieu Le <thieule@chromium.org>
diff --git a/device_unittest.cc b/device_unittest.cc
index 180c12a..1c3f5d4 100644
--- a/device_unittest.cc
+++ b/device_unittest.cc
@@ -29,6 +29,7 @@
 #include "shill/mock_ipconfig.h"
 #include "shill/mock_manager.h"
 #include "shill/mock_portal_detector.h"
+#include "shill/mock_routing_table.h"
 #include "shill/mock_rtnl_handler.h"
 #include "shill/mock_service.h"
 #include "shill/mock_store.h"
@@ -59,7 +60,7 @@
                            manager(),
                            kDeviceName,
                            kDeviceAddress,
-                           0,
+                           kDeviceInterfaceIndex,
                            Technology::kUnknown)),
         device_info_(control_interface(), NULL, NULL, NULL) {
     DHCPProvider::GetInstance()->glib_ = glib();
@@ -68,12 +69,14 @@
   virtual ~DeviceTest() {}
 
   virtual void SetUp() {
+    device_->routing_table_ = &routing_table_;
     device_->rtnl_handler_ = &rtnl_handler_;
   }
 
  protected:
   static const char kDeviceName[];
   static const char kDeviceAddress[];
+  static const int kDeviceInterfaceIndex;
 
   void OnIPConfigUpdated(const IPConfigRefPtr &ipconfig, bool success) {
     device_->OnIPConfigUpdated(ipconfig, success);
@@ -90,11 +93,13 @@
   MockControl control_interface_;
   DeviceRefPtr device_;
   MockDeviceInfo device_info_;
+  MockRoutingTable routing_table_;
   StrictMock<MockRTNLHandler> rtnl_handler_;
 };
 
 const char DeviceTest::kDeviceName[] = "testdevice";
 const char DeviceTest::kDeviceAddress[] = "address";
+const int DeviceTest::kDeviceInterfaceIndex = 0;
 
 TEST_F(DeviceTest, Contains) {
   EXPECT_TRUE(device_->store().Contains(flimflam::kNameProperty));
@@ -300,6 +305,11 @@
   OnIPConfigUpdated(ipconfig.get(), true);
 }
 
+TEST_F(DeviceTest, Start) {
+  EXPECT_CALL(routing_table_, FlushRoutes(kDeviceInterfaceIndex));
+  device_->Start();
+}
+
 TEST_F(DeviceTest, Stop) {
   device_->ipconfig_ = new IPConfig(&control_interface_, kDeviceName);
   scoped_refptr<MockService> service(